1 | <?php |
||
11 | class Validator { |
||
12 | |||
13 | public $file; |
||
14 | |||
15 | public $error = ''; |
||
16 | |||
17 | public $process = ''; |
||
18 | |||
19 | public $output; |
||
20 | |||
21 | public $executable; |
||
22 | |||
23 | 6 | public function __construct($file, $executable = 'pdftocairo') |
|
24 | { |
||
25 | 6 | $this->executable = $executable; |
|
26 | 6 | $this->checkExecutable(); |
|
27 | 5 | if (!is_file($file)) { |
|
28 | 1 | throw new FileNotFound($file); |
|
29 | } |
||
30 | 4 | if (!self::is_pdf($file)) { |
|
31 | 1 | throw new MimeTypeIsNotPdf($file); |
|
32 | } |
||
33 | 3 | $this->file = $file; |
|
34 | 3 | } |
|
35 | |||
36 | 6 | public function checkExecutable() |
|
37 | { |
||
38 | 6 | $process = new Process('which ' . $this->executable); |
|
39 | 6 | $process->run(); |
|
40 | 6 | if (!$process->isSuccessful()) { |
|
41 | 1 | throw new BinaryNotFound($process); |
|
42 | } |
||
43 | |||
44 | 5 | return true; |
|
45 | } |
||
46 | |||
47 | |||
48 | 4 | public static function is_pdf($file) |
|
53 | |||
54 | 3 | public function check() |
|
78 | |||
79 | } |
||
80 |