Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
URIAction
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getActionType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Action;
6
7use Phpdftk\Pdf\Core\PdfBoolean;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfString;
11
12/**
13 * URI action (/S /URI).
14 * Opens a URL in the user's browser.
15 */
16class URIAction extends Action
17{
18    public PdfString $uri;        // /URI - required
19    public ?bool $isMap = null;   // /IsMap
20
21    public function __construct(PdfString $uri)
22    {
23        $this->uri = $uri;
24    }
25
26    public function getActionType(): string
27    {
28        return 'URI';
29    }
30
31    public function toPdf(): string
32    {
33        $dict = new PdfDictionary();
34        $dict->set('Type', new PdfName(self::PDF_TYPE));
35        $dict->set('S', new PdfName($this->getActionType()));
36        $dict->set('URI', $this->uri);
37
38        if ($this->isMap !== null) {
39            $dict->set('IsMap', new PdfBoolean($this->isMap));
40        }
41        if ($this->next !== null) {
42            $dict->set('Next', $this->next);
43        }
44
45        return $dict->toPdf();
46    }
47}