1 | <?php |
||
23 | class Ghostscript |
||
24 | { |
||
25 | /** |
||
26 | * The default binary. |
||
27 | */ |
||
28 | const DEFAULT_BINARY = 'gs'; |
||
29 | |||
30 | /** |
||
31 | * The versions. |
||
32 | * |
||
33 | * @var string[] |
||
34 | */ |
||
35 | protected static $versions = []; |
||
36 | |||
37 | /** |
||
38 | * The options. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $options; |
||
43 | |||
44 | /** |
||
45 | * Create Ghostscript object. |
||
46 | * |
||
47 | * @param array $options |
||
48 | * |
||
49 | * @throws \RuntimeException |
||
50 | 28 | */ |
|
51 | public function __construct(array $options = []) |
||
52 | 28 | { |
|
53 | $this->options = $options; |
||
54 | 28 | ||
55 | 2 | if (version_compare('9.00', $this->getVersion()) > 0) { |
|
56 | throw new \RuntimeException('Ghostscript version 9.00 or higher is required'); |
||
57 | 24 | } |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get option. |
||
62 | * |
||
63 | * @param string $name |
||
64 | * @param mixed $default |
||
65 | * |
||
66 | * @return mixed |
||
67 | 26 | */ |
|
68 | public function getOption($name, $default = null) |
||
69 | 26 | { |
|
70 | 10 | if (array_key_exists($name, $this->options)) { |
|
71 | return $this->options[$name]; |
||
72 | } |
||
73 | 24 | ||
74 | return $default; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get process to identify version. |
||
79 | * |
||
80 | * @param string $binary |
||
81 | * |
||
82 | * @return Process |
||
83 | 2 | */ |
|
84 | protected function createProcessToIdentifyVersion($binary) |
||
85 | 2 | { |
|
86 | return new Process($binary . ' --version'); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get version. |
||
91 | * |
||
92 | * @throws \RuntimeException |
||
93 | * |
||
94 | * @return string |
||
95 | 26 | */ |
|
96 | public function getVersion() |
||
113 | |||
114 | /** |
||
115 | * Create arguments object. |
||
116 | * |
||
117 | * @return Arguments |
||
118 | 16 | */ |
|
119 | protected function createArguments() |
||
129 | |||
130 | /** |
||
131 | * Create PDF device object. |
||
132 | * |
||
133 | * @param null|string $outputFile |
||
134 | * |
||
135 | * @return PdfWrite |
||
136 | 8 | */ |
|
137 | public function createPdfDevice($outputFile = null) |
||
153 | |||
154 | /** |
||
155 | * Create no display device object. |
||
156 | * |
||
157 | * @return NoDisplay |
||
158 | 2 | */ |
|
159 | public function createNoDisplayDevice() |
||
163 | |||
164 | /** |
||
165 | * Create PDF info device object. |
||
166 | * |
||
167 | * @param string $pdfInfoPath Path to toolbin/pdf_info.ps |
||
168 | * |
||
169 | * @return PdfInfo |
||
170 | 2 | */ |
|
171 | public function createPdfInfoDevice($pdfInfoPath) |
||
175 | |||
176 | /** |
||
177 | * Create bounding box info device object. |
||
178 | * |
||
179 | * @return BoundingBoxInfo |
||
180 | 2 | */ |
|
181 | public function createBoundingBoxInfoDevice() |
||
191 | |||
192 | /** |
||
193 | * Create inkcov device object |
||
194 | * |
||
195 | * @return Inkcov |
||
196 | */ |
||
197 | public function createInkcovDevice() |
||
209 | } |
||
210 |