Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| PdfEActionConstraint | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| check | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Conformance\Constraint; |
| 6 | |
| 7 | use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector; |
| 8 | use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile; |
| 9 | use Phpdftk\Pdf\Conformance\Result\ConformanceViolation; |
| 10 | use Phpdftk\Pdf\Conformance\Result\ViolationSeverity; |
| 11 | use Phpdftk\Pdf\Core\Action\JavaScriptAction; |
| 12 | use 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 | */ |
| 20 | final 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 | } |