1 | <?php declare(strict_types=1); |
||
9 | class Wkhtml |
||
10 | { |
||
11 | use LoggerAwareTrait; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $tempPath = ''; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $tempFile = ''; |
||
18 | |||
19 | /** @var bool */ |
||
20 | protected $doCacheFile = true; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $wkhtmlBinary = ''; |
||
24 | |||
25 | /** @var string */ |
||
26 | protected $wkhtmlArgs = ''; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $orientation = 'portrait'; |
||
30 | |||
31 | /** @var string */ |
||
32 | protected $uriSource = ''; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $fileSource = ''; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $stringSource = ''; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $content = ''; |
||
42 | |||
43 | /** @var bool */ |
||
44 | protected $generated = false; |
||
45 | |||
46 | /** @var array */ |
||
47 | protected $xvfbLocations = [ |
||
48 | '/usr/bin/xvfb-run', // Ubuntu |
||
49 | ]; |
||
50 | |||
51 | /** @var null|string */ |
||
52 | protected $xvfbBinary = '/usr/bin/xvfb-run'; |
||
53 | |||
54 | /** @var null|string */ |
||
55 | protected $xvfbArgs = '--server-args="-screen 0, 1024x768x24"'; |
||
56 | protected $xvfbLog = null; |
||
57 | |||
58 | /** @var array */ |
||
59 | protected $wkhtmlLocations = [ |
||
60 | '/usr/bin/wkhtmltopdf', // Ubuntu |
||
61 | '/usr/local/bin/wkhtmltopdf', // Mac |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * @param array $settings |
||
66 | */ |
||
67 | public function __construct(array $settings) |
||
84 | |||
85 | /** |
||
86 | * @param string $wkhtmlBinary |
||
87 | * @return string |
||
88 | */ |
||
89 | protected function findWkhtml(string $wkhtmlBinary) : string |
||
105 | |||
106 | /** |
||
107 | * @param string $xvfbBinary |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function findXvfb(string $xvfbBinary='') : string |
||
126 | |||
127 | /** |
||
128 | * @param string $wkhtmlBinary |
||
129 | * @return Wkhtml |
||
130 | */ |
||
131 | public function wkhtmlBinary(string $wkhtmlBinary) : Wkhtml |
||
138 | |||
139 | /** |
||
140 | * @param string $wkhtmlArgs |
||
141 | * @return Wkhtml |
||
142 | */ |
||
143 | public function wkhtmlArgs(string $wkhtmlArgs) : Wkhtml |
||
149 | |||
150 | /** |
||
151 | * @param string $xvfbBinary |
||
152 | * @return Wkhtml |
||
153 | */ |
||
154 | public function xvfbBinary(string $xvfbBinary) : Wkhtml |
||
161 | |||
162 | /** |
||
163 | * @param string $xvfbArgs |
||
164 | * @return Wkhtml |
||
165 | */ |
||
166 | public function xvfbArgs(string $xvfbArgs) : Wkhtml |
||
172 | |||
173 | /** |
||
174 | * @param string $source |
||
175 | * @return Wkhtml |
||
176 | */ |
||
177 | public function fromUri(string $source) : Wkhtml |
||
186 | |||
187 | /** |
||
188 | * @param string $source |
||
189 | * @return Wkhtml |
||
190 | */ |
||
191 | public function fromFile(string $source) : Wkhtml |
||
200 | |||
201 | /** |
||
202 | * @param string $source |
||
203 | * @return Wkhtml |
||
204 | */ |
||
205 | public function fromString(string $source) : Wkhtml |
||
214 | |||
215 | /** |
||
216 | * @param string $orientation |
||
217 | * @return Wkhtml |
||
218 | */ |
||
219 | public function orientation(string $orientation) : Wkhtml |
||
228 | |||
229 | /** |
||
230 | * @return Wkhtml |
||
231 | * @throws \Exception |
||
232 | */ |
||
233 | public function generate() |
||
271 | |||
272 | /** |
||
273 | * @param string|null $fileName |
||
274 | */ |
||
275 | public function toBrowser(string $fileName='pdf_file') |
||
284 | |||
285 | /** |
||
286 | * @param string $fullPath |
||
287 | * @return bool |
||
288 | * @throws \Exception |
||
289 | */ |
||
290 | public function toFile(string $fullPath) : bool |
||
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | * @throws \Exception |
||
305 | */ |
||
306 | public function toString() : string |
||
313 | |||
314 | /** |
||
315 | * @param string $message |
||
316 | * @param array $context |
||
317 | * @throws \Exception |
||
318 | */ |
||
319 | protected function error(string $message, array $context=[]) |
||
325 | } |
||
326 |
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: