Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ActionConstraint
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
1 / 1
10
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
1 / 1
10
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;
13use Phpdftk\Pdf\Core\Action\MovieAction;
14use Phpdftk\Pdf\Core\Action\SoundAction;
15use Phpdftk\Pdf\Core\Action\RichMediaExecuteAction;
16use Phpdftk\Pdf\Core\Action\RenditionAction;
17
18/**
19 * PDF/A clause 6.5 / 6.6.1: Restricted action types.
20 *
21 * All PDF/A levels prohibit:
22 *   - JavaScript actions
23 *   - Launch actions (external application execution)
24 *
25 * PDF/A-1 additionally prohibits:
26 *   - Movie actions
27 *   - Sound actions
28 *   - Rendition actions
29 *   - RichMediaExecute actions
30 */
31final class ActionConstraint implements ConformanceConstraint
32{
33    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
34    {
35        $violations = [];
36
37        foreach ($inspector->getRegisteredObjects() as $object) {
38            if ($object instanceof JavaScriptAction) {
39                $violations[] = new ConformanceViolation(
40                    clause: '6.6.1',
41                    message: 'JavaScript actions are prohibited in ' . $profile->getFamily(),
42                    severity: ViolationSeverity::Error,
43                    objectPath: 'Action[JavaScript]',
44                );
45            }
46
47            if ($object instanceof LaunchAction) {
48                $violations[] = new ConformanceViolation(
49                    clause: '6.6.1',
50                    message: 'Launch actions are prohibited in ' . $profile->getFamily(),
51                    severity: ViolationSeverity::Error,
52                    objectPath: 'Action[Launch]',
53                );
54            }
55
56            // PDF/A-1 is stricter about multimedia actions
57            if ($profile instanceof \Phpdftk\Pdf\Conformance\Profile\PdfAProfile
58                && $profile->getPart() === 1
59            ) {
60                if ($object instanceof MovieAction) {
61                    $violations[] = new ConformanceViolation(
62                        clause: '6.5',
63                        message: 'Movie actions are prohibited in PDF/A-1',
64                        severity: ViolationSeverity::Error,
65                        objectPath: 'Action[Movie]',
66                    );
67                }
68                if ($object instanceof SoundAction) {
69                    $violations[] = new ConformanceViolation(
70                        clause: '6.5',
71                        message: 'Sound actions are prohibited in PDF/A-1',
72                        severity: ViolationSeverity::Error,
73                        objectPath: 'Action[Sound]',
74                    );
75                }
76                if ($object instanceof RenditionAction) {
77                    $violations[] = new ConformanceViolation(
78                        clause: '6.5',
79                        message: 'Rendition actions are prohibited in PDF/A-1',
80                        severity: ViolationSeverity::Error,
81                        objectPath: 'Action[Rendition]',
82                    );
83                }
84                if ($object instanceof RichMediaExecuteAction) {
85                    $violations[] = new ConformanceViolation(
86                        clause: '6.5',
87                        message: 'RichMediaExecute actions are prohibited in PDF/A-1',
88                        severity: ViolationSeverity::Error,
89                        objectPath: 'Action[RichMediaExecute]',
90                    );
91                }
92            }
93        }
94
95        return $violations;
96    }
97}