1 | <?php |
||
10 | class Wkhtml |
||
11 | { |
||
12 | use LoggerTrait; |
||
13 | |||
14 | /** @var string */ |
||
15 | protected $tempPath = ''; |
||
16 | |||
17 | /** @var string */ |
||
18 | protected $tempFile = ''; |
||
19 | |||
20 | /** @var bool */ |
||
21 | protected $doCacheFile = true; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $wkhtmlBinary = ''; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $wkhtmlArgs = ''; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $orientation = 'portrait'; |
||
31 | |||
32 | /** @var string */ |
||
33 | protected $uriSource = ''; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $fileSource = ''; |
||
37 | |||
38 | /** @var string */ |
||
39 | protected $stringSource = ''; |
||
40 | |||
41 | /** @var string */ |
||
42 | protected $content = ''; |
||
43 | |||
44 | /** @var bool */ |
||
45 | protected $generated = false; |
||
46 | |||
47 | /** @var array */ |
||
48 | protected $xvfbLocations = [ |
||
49 | '/usr/bin/xvfb-run', // Ubuntu |
||
50 | ]; |
||
51 | |||
52 | /** @var null|string */ |
||
53 | protected $xvfbBinary = '/usr/bin/xvfb-run'; |
||
54 | |||
55 | /** @var null|string */ |
||
56 | protected $xvfbArgs = '--server-args="-screen 0, 1024x768x24"'; |
||
57 | protected $xvfbLog = null; |
||
58 | |||
59 | /** @var array */ |
||
60 | protected $wkhtmlLocations = [ |
||
61 | '/usr/bin/wkhtmltopdf', // Ubuntu |
||
62 | '/usr/local/bin/wkhtmltopdf', // Mac |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * @param array $settings |
||
67 | */ |
||
68 | public function __construct(array $settings) |
||
87 | |||
88 | /** |
||
89 | * @param string $wkhtmlBinary |
||
90 | * @return string|null |
||
91 | */ |
||
92 | protected function findWkhtml($wkhtmlBinary) |
||
107 | |||
108 | /** |
||
109 | * @param string $xvfbBinary |
||
110 | * @return string|null |
||
111 | */ |
||
112 | protected function findXvfb($xvfbBinary=null) |
||
127 | |||
128 | /** |
||
129 | * @param string $wkhtmlBinary |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function wkhtmlBinary($wkhtmlBinary) |
||
138 | |||
139 | /** |
||
140 | * @param string $wkhtmlArgs |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function wkhtmlArgs($wkhtmlArgs) |
||
148 | |||
149 | /** |
||
150 | * @param string $xvfbBinary |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function xvfbBinary($xvfbBinary) |
||
159 | |||
160 | /** |
||
161 | * @param string $xvfbArgs |
||
162 | * @return $this |
||
163 | */ |
||
164 | public function xvfbArgs($xvfbArgs) |
||
169 | |||
170 | /** |
||
171 | * @param string $tempPath |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function tempPath($tempPath) |
||
185 | |||
186 | /** |
||
187 | * @param string $tempFile |
||
188 | * @param bool $doCacheFile |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function tempFile($tempFile, $doCacheFile=true) |
||
201 | |||
202 | /** |
||
203 | * @param string $source |
||
204 | * @return $this |
||
205 | */ |
||
206 | public function fromUri($source) |
||
214 | |||
215 | /** |
||
216 | * @param string $source |
||
217 | * @return $this |
||
218 | */ |
||
219 | public function fromFile($source) |
||
227 | |||
228 | /** |
||
229 | * @param string $source |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function fromString($source) |
||
240 | |||
241 | /** |
||
242 | * @param string $orientation |
||
243 | * @return $this |
||
244 | */ |
||
245 | public function orientation($orientation) |
||
253 | |||
254 | /** |
||
255 | * @return $this|bool |
||
256 | * @throws \Exception |
||
257 | */ |
||
258 | public function generate() |
||
291 | |||
292 | /** |
||
293 | * @param string $fullTempPath |
||
294 | * @return bool |
||
295 | * @throws \Exception |
||
296 | */ |
||
297 | protected function saveStringSourceToFile($fullTempPath) |
||
309 | |||
310 | /** |
||
311 | * @param string|null $fileName |
||
312 | */ |
||
313 | public function toBrowser($fileName=null) |
||
322 | |||
323 | /** |
||
324 | * @param string $fullPath |
||
325 | * @return bool |
||
326 | * @throws \Exception |
||
327 | */ |
||
328 | public function toFile($fullPath) |
||
338 | |||
339 | /** |
||
340 | * @return string |
||
341 | * @throws \Exception |
||
342 | */ |
||
343 | public function toString() |
||
351 | |||
352 | /** |
||
353 | * @return string |
||
354 | */ |
||
355 | protected function getTempFullPath() |
||
359 | |||
360 | /** |
||
361 | * @param string $message |
||
362 | * @param array $context |
||
363 | * @throws \Exception |
||
364 | */ |
||
365 | protected function error($message, array $context=[]) |
||
371 | } |
||
372 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: