Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ConformanceChecker
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 open
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 openString
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 checkProfile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 checkProfiles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getReader
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Conformance;
6
7use Phpdftk\Pdf\Conformance\Inspection\ReaderDocumentInspector;
8use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile;
9use Phpdftk\Pdf\Conformance\Result\ConformanceResult;
10use Phpdftk\Pdf\Conformance\Validator\ConformanceValidator;
11use Phpdftk\Pdf\Reader\PdfReader;
12
13/**
14 * High-level conformance checker for existing PDFs.
15 *
16 * Loads a PDF via PdfReader and validates it against one or more
17 * conformance profiles, returning structured results.
18 *
19 * Usage:
20 *   $results = ConformanceChecker::open('document.pdf')
21 *       ->checkProfile(PdfAProfile::A1b);
22 *
23 *   $results = ConformanceChecker::openString($bytes)
24 *       ->checkProfiles([PdfAProfile::A2b, PdfUaProfile::UA1]);
25 *
26 * @api
27 */
28final class ConformanceChecker
29{
30    private readonly ReaderDocumentInspector $inspector;
31    private readonly ConformanceValidator $validator;
32
33    private function __construct(
34        private readonly PdfReader $reader,
35    ) {
36        $this->inspector = new ReaderDocumentInspector($reader);
37        $this->validator = new ConformanceValidator();
38    }
39
40    /**
41     * Open a PDF file for conformance checking.
42     */
43    public static function open(string $path, string $password = ''): self
44    {
45        $reader = PdfReader::fromFile($path, $password);
46        return new self($reader);
47    }
48
49    /**
50     * Open a PDF from a byte string for conformance checking.
51     */
52    public static function openString(string $bytes, string $password = ''): self
53    {
54        $reader = PdfReader::fromString($bytes, $password);
55        return new self($reader);
56    }
57
58    /**
59     * Check the PDF against a single conformance profile.
60     */
61    public function checkProfile(ConformanceProfile $profile): ConformanceResult
62    {
63        return $this->validator->validate($this->inspector, $profile);
64    }
65
66    /**
67     * Check the PDF against multiple conformance profiles.
68     *
69     * @param ConformanceProfile[] $profiles
70     * @return list<ConformanceResult>
71     */
72    public function checkProfiles(array $profiles): array
73    {
74        return $this->validator->validateAll($this->inspector, $profiles);
75    }
76
77    /**
78     * Get the underlying PdfReader for additional inspection.
79     */
80    public function getReader(): PdfReader
81    {
82        return $this->reader;
83    }
84}