Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PdfEActionConstraint
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Conformance\Constraint;
6
7use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector;
8use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile;
9use Phpdftk\Pdf\Conformance\Result\ConformanceViolation;
10use Phpdftk\Pdf\Conformance\Result\ViolationSeverity;
11use Phpdftk\Pdf\Core\Action\JavaScriptAction;
12use Phpdftk\Pdf\Core\Action\LaunchAction;
13
14/**
15 * ISO 24517-1 (PDF/E-1): Action restrictions.
16 *
17 * PDF/E-1 prohibits JavaScript and Launch actions. GoTo, URI, GoToR,
18 * and GoToE actions are permitted.
19 */
20final class PdfEActionConstraint implements ConformanceConstraint
21{
22    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
23    {
24        $violations = [];
25
26        foreach ($inspector->getRegisteredObjects() as $object) {
27            if ($object instanceof JavaScriptAction) {
28                $violations[] = new ConformanceViolation(
29                    clause: '6.6',
30                    message: 'JavaScript actions are prohibited in PDF/E-1',
31                    severity: ViolationSeverity::Error,
32                    objectPath: 'Action[JavaScript]',
33                );
34            }
35
36            if ($object instanceof LaunchAction) {
37                $violations[] = new ConformanceViolation(
38                    clause: '6.6',
39                    message: 'Launch actions are prohibited in PDF/E-1',
40                    severity: ViolationSeverity::Error,
41                    objectPath: 'Action[Launch]',
42                );
43            }
44        }
45
46        return $violations;
47    }
48}