Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Action
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getActionType
n/a
0 / 0
n/a
0 / 0
0
 baseDictionary
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Action;
6
7use Phpdftk\Pdf\Core\PdfDictionary;
8use Phpdftk\Pdf\Core\PdfName;
9use Phpdftk\Pdf\Core\PdfObject;
10use Phpdftk\Pdf\Core\PdfReference;
11
12/**
13 * Abstract base class for all PDF action types (/Type /Action).
14 */
15abstract class Action extends PdfObject
16{
17    public const PDF_TYPE = 'Action';
18
19    /**
20     * Returns the /S (action type) value for this action.
21     */
22    abstract public function getActionType(): string;
23
24    public ?PdfReference $next = null; // /Next - next action to perform
25
26    /**
27     * Build a dictionary pre-populated with the common /Type, /S, and /Next
28     * entries so subclasses only need to add their subtype-specific fields.
29     */
30    protected function baseDictionary(): PdfDictionary
31    {
32        $dict = new PdfDictionary();
33        $dict->set('Type', new PdfName(self::PDF_TYPE));
34        $dict->set('S', new PdfName($this->getActionType()));
35        if ($this->next !== null) {
36            $dict->set('Next', $this->next);
37        }
38        return $dict;
39    }
40}