| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package dompdf |
| 5 |
* @link https://github.com/dompdf/dompdf |
| 6 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 7 |
*/ |
| 8 |
namespace WCPOS\Vendor\Dompdf; |
| 9 |
|
| 10 |
class Options |
| 11 |
{ |
| 12 |
/** |
| 13 |
* The root of your DOMPDF installation |
| 14 |
* |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
private $rootDir; |
| 18 |
/** |
| 19 |
* The location of a temporary directory. |
| 20 |
* |
| 21 |
* The directory specified must be writable by the executing process. |
| 22 |
* The temporary directory is required to download remote images and when |
| 23 |
* using the PFDLib back end. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
private $tempDir; |
| 28 |
/** |
| 29 |
* The location of the DOMPDF font directory |
| 30 |
* |
| 31 |
* The location of the directory where DOMPDF will store fonts and font metrics |
| 32 |
* Note: This directory must exist and be writable by the executing process. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
private $fontDir; |
| 37 |
/** |
| 38 |
* The location of the DOMPDF font cache directory |
| 39 |
* |
| 40 |
* This directory contains the cached font metrics for the fonts used by DOMPDF. |
| 41 |
* This directory can be the same as $fontDir |
| 42 |
* |
| 43 |
* Note: This directory must exist and be writable by the executing process. |
| 44 |
* |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
private $fontCache; |
| 48 |
/** |
| 49 |
* dompdf's "chroot" |
| 50 |
* |
| 51 |
* Utilized by Dompdf's default file:// protocol URI validation rule. |
| 52 |
* All local files opened by dompdf must be in a subdirectory of the directory |
| 53 |
* or directories specified by this option. |
| 54 |
* DO NOT set this value to '/' since this could allow an attacker to use dompdf to |
| 55 |
* read any files on the server. This should be an absolute path. |
| 56 |
* |
| 57 |
* ==== IMPORTANT ==== |
| 58 |
* This setting may increase the risk of system exploit. Do not change |
| 59 |
* this settings without understanding the consequences. Additional |
| 60 |
* documentation is available on the dompdf wiki at: |
| 61 |
* https://github.com/dompdf/dompdf/wiki |
| 62 |
* |
| 63 |
* @var array |
| 64 |
*/ |
| 65 |
private $chroot; |
| 66 |
/** |
| 67 |
* Protocol whitelist |
| 68 |
* |
| 69 |
* Protocols and PHP wrappers allowed in URIs, and the validation rules |
| 70 |
* that determine if a resource may be loaded. Full support is not guaranteed |
| 71 |
* for the protocols/wrappers specified |
| 72 |
* by this array. |
| 73 |
* |
| 74 |
* @var array |
| 75 |
*/ |
| 76 |
private $allowedProtocols = ["data://" => ["rules" => []], "file://" => ["rules" => []], "http://" => ["rules" => []], "https://" => ["rules" => []]]; |
| 77 |
/** |
| 78 |
* Operational artifact (log files, temporary files) path validation |
| 79 |
* |
| 80 |
* @var callable |
| 81 |
*/ |
| 82 |
private $artifactPathValidation = null; |
| 83 |
/** |
| 84 |
* @var string |
| 85 |
*/ |
| 86 |
private $logOutputFile = ''; |
| 87 |
/** |
| 88 |
* Styles targeted to this media type are applied to the document. |
| 89 |
* This is on top of the media types that are always applied: |
| 90 |
* all, static, visual, bitmap, paged, dompdf |
| 91 |
* |
| 92 |
* @var string |
| 93 |
*/ |
| 94 |
private $defaultMediaType = "screen"; |
| 95 |
/** |
| 96 |
* The default paper size. |
| 97 |
* |
| 98 |
* North America standard is "letter"; other countries generally "a4" |
| 99 |
* @see \Dompdf\Adapter\CPDF::PAPER_SIZES for valid sizes |
| 100 |
* |
| 101 |
* @var string|float[] |
| 102 |
*/ |
| 103 |
private $defaultPaperSize = "letter"; |
| 104 |
/** |
| 105 |
* The default paper orientation. |
| 106 |
* |
| 107 |
* The orientation of the page (portrait or landscape). |
| 108 |
* |
| 109 |
* @var string |
| 110 |
*/ |
| 111 |
private $defaultPaperOrientation = "portrait"; |
| 112 |
/** |
| 113 |
* The default font family |
| 114 |
* |
| 115 |
* Used if no suitable fonts can be found. This must exist in the font folder. |
| 116 |
* |
| 117 |
* @var string |
| 118 |
*/ |
| 119 |
private $defaultFont = "serif"; |
| 120 |
/** |
| 121 |
* Image DPI setting |
| 122 |
* |
| 123 |
* This setting determines the default DPI setting for images and fonts. The |
| 124 |
* DPI may be overridden for inline images by explicitly setting the |
| 125 |
* image's width & height style attributes (i.e. if the image's native |
| 126 |
* width is 600 pixels and you specify the image's width as 72 points, |
| 127 |
* the image will have a DPI of 600 in the rendered PDF. The DPI of |
| 128 |
* background images can not be overridden and is controlled entirely |
| 129 |
* via this parameter. |
| 130 |
* |
| 131 |
* For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI). |
| 132 |
* If a size in html is given as px (or without unit as image size), |
| 133 |
* this tells the corresponding size in pt at 72 DPI. |
| 134 |
* This adjusts the relative sizes to be similar to the rendering of the |
| 135 |
* html page in a reference browser. |
| 136 |
* |
| 137 |
* In pdf, always 1 pt = 1/72 inch |
| 138 |
* |
| 139 |
* @var int |
| 140 |
*/ |
| 141 |
private $dpi = 96; |
| 142 |
/** |
| 143 |
* A ratio applied to the fonts height to be more like browsers' line height |
| 144 |
* |
| 145 |
* @var float |
| 146 |
*/ |
| 147 |
private $fontHeightRatio = 1.1; |
| 148 |
/** |
| 149 |
* The maximum estimated in-memory size of an image allowed to be rendered, in bytes. |
| 150 |
* |
| 151 |
* @var int |
| 152 |
*/ |
| 153 |
private $imageByteSizeLimit = -1; |
| 154 |
/** |
| 155 |
* Enable embedded PHP |
| 156 |
* |
| 157 |
* If this setting is set to true then DOMPDF will automatically evaluate |
| 158 |
* embedded PHP contained within <script type="text/php"> ... </script> tags. |
| 159 |
* |
| 160 |
* ==== IMPORTANT ==== |
| 161 |
* Enabling this for documents you do not trust (e.g. arbitrary remote html |
| 162 |
* pages) is a security risk. Embedded scripts are run with the same level of |
| 163 |
* system access available to dompdf. Set this option to false (recommended) |
| 164 |
* if you wish to process untrusted documents. |
| 165 |
* |
| 166 |
* This setting may increase the risk of system exploit. Do not change |
| 167 |
* this settings without understanding the consequences. Additional |
| 168 |
* documentation is available on the dompdf wiki at: |
| 169 |
* https://github.com/dompdf/dompdf/wiki |
| 170 |
* |
| 171 |
* @var bool |
| 172 |
*/ |
| 173 |
private $isPhpEnabled = \false; |
| 174 |
/** |
| 175 |
* Enable remote file access |
| 176 |
* |
| 177 |
* If this setting is set to true, DOMPDF will access remote sites for |
| 178 |
* images and CSS files as required. |
| 179 |
* |
| 180 |
* ==== IMPORTANT ==== |
| 181 |
* This can be a security risk, in particular in combination with isPhpEnabled and |
| 182 |
* allowing remote html code to be passed to $dompdf = new DOMPDF(); $dompdf->load_html(...); |
| 183 |
* This allows anonymous users to download legally doubtful internet content which on |
| 184 |
* tracing back appears to being downloaded by your server, or allows malicious php code |
| 185 |
* in remote html pages to be executed by your server with your account privileges. |
| 186 |
* |
| 187 |
* This setting may increase the risk of system exploit. Do not change |
| 188 |
* this settings without understanding the consequences. Additional |
| 189 |
* documentation is available on the dompdf wiki at: |
| 190 |
* https://github.com/dompdf/dompdf/wiki |
| 191 |
* |
| 192 |
* @var bool |
| 193 |
*/ |
| 194 |
private $isRemoteEnabled = \false; |
| 195 |
/** |
| 196 |
* List of allowed remote hosts |
| 197 |
* |
| 198 |
* Each value of the array must be a valid hostname. |
| 199 |
* |
| 200 |
* This will be used to filter which resources can be loaded in combination with |
| 201 |
* isRemoteEnabled. If isRemoteEnabled is FALSE, then this will have no effect. |
| 202 |
* |
| 203 |
* Leave to NULL to allow any remote host. |
| 204 |
* |
| 205 |
* @var array|null |
| 206 |
*/ |
| 207 |
private $allowedRemoteHosts = null; |
| 208 |
/** |
| 209 |
* Enable PDF/A-3 compliance mode |
| 210 |
* |
| 211 |
* ==== EXPERIMENTAL ==== |
| 212 |
* This feature is currently only supported with the CPDF backend and will |
| 213 |
* have no effect if used with any other. |
| 214 |
* |
| 215 |
* Currently this mode only takes care of adding the necessary metadata, output intents, etc. |
| 216 |
* It does not enforce font embedding, it's up to you to embed the fonts you plan on using. |
| 217 |
* |
| 218 |
* @var bool |
| 219 |
*/ |
| 220 |
private $isPdfAEnabled = \false; |
| 221 |
/** |
| 222 |
* Enable inline JavaScript |
| 223 |
* |
| 224 |
* If this setting is set to true then DOMPDF will automatically insert |
| 225 |
* JavaScript code contained within <script type="text/javascript"> ... </script> |
| 226 |
* tags as written into the PDF. |
| 227 |
* |
| 228 |
* NOTE: This is PDF-based JavaScript to be executed by the PDF viewer, |
| 229 |
* not browser-based JavaScript executed by Dompdf. |
| 230 |
* |
| 231 |
* @var bool |
| 232 |
*/ |
| 233 |
private $isJavascriptEnabled = \true; |
| 234 |
/** |
| 235 |
* Use the HTML5 Lib parser |
| 236 |
* |
| 237 |
* @deprecated |
| 238 |
* @var bool |
| 239 |
*/ |
| 240 |
private $isHtml5ParserEnabled = \true; |
| 241 |
/** |
| 242 |
* Whether to enable font subsetting or not. |
| 243 |
* |
| 244 |
* @var bool |
| 245 |
*/ |
| 246 |
private $isFontSubsettingEnabled = \true; |
| 247 |
/** |
| 248 |
* @var bool |
| 249 |
*/ |
| 250 |
private $debugPng = \false; |
| 251 |
/** |
| 252 |
* @var bool |
| 253 |
*/ |
| 254 |
private $debugKeepTemp = \false; |
| 255 |
/** |
| 256 |
* @var bool |
| 257 |
*/ |
| 258 |
private $debugCss = \false; |
| 259 |
/** |
| 260 |
* @var bool |
| 261 |
*/ |
| 262 |
private $debugLayout = \false; |
| 263 |
/** |
| 264 |
* @var bool |
| 265 |
*/ |
| 266 |
private $debugLayoutLines = \true; |
| 267 |
/** |
| 268 |
* @var bool |
| 269 |
*/ |
| 270 |
private $debugLayoutBlocks = \true; |
| 271 |
/** |
| 272 |
* @var bool |
| 273 |
*/ |
| 274 |
private $debugLayoutInline = \true; |
| 275 |
/** |
| 276 |
* @var bool |
| 277 |
*/ |
| 278 |
private $debugLayoutPaddingBox = \true; |
| 279 |
/** |
| 280 |
* The PDF rendering backend to use |
| 281 |
* |
| 282 |
* Valid settings are 'PDFLib', 'CPDF', 'GD', and 'auto'. 'auto' will |
| 283 |
* look for PDFLib and use it if found, or if not it will fall back on |
| 284 |
* CPDF. 'GD' renders PDFs to graphic files. {@link Dompdf\CanvasFactory} |
| 285 |
* ultimately determines which rendering class to instantiate |
| 286 |
* based on this setting. |
| 287 |
* |
| 288 |
* @var string |
| 289 |
*/ |
| 290 |
private $pdfBackend = "CPDF"; |
| 291 |
/** |
| 292 |
* PDFlib license key |
| 293 |
* |
| 294 |
* If you are using a licensed, commercial version of PDFlib, specify |
| 295 |
* your license key here. If you are using PDFlib-Lite or are evaluating |
| 296 |
* the commercial version of PDFlib, comment out this setting. |
| 297 |
* |
| 298 |
* @link http://www.pdflib.com |
| 299 |
* |
| 300 |
* If pdflib present in web server and auto or selected explicitly above, |
| 301 |
* a real license code must exist! |
| 302 |
* |
| 303 |
* @var string |
| 304 |
*/ |
| 305 |
private $pdflibLicense = ""; |
| 306 |
/** |
| 307 |
* HTTP context created with stream_context_create() |
| 308 |
* Will be used for file_get_contents |
| 309 |
* |
| 310 |
* @link https://www.php.net/manual/context.php |
| 311 |
* |
| 312 |
* @var resource |
| 313 |
*/ |
| 314 |
private $httpContext; |
| 315 |
/** |
| 316 |
* @param array $attributes |
| 317 |
*/ |
| 318 |
public function __construct(?array $attributes = null) |
| 319 |
{ |
| 320 |
$rootDir = \realpath(__DIR__ . "/../"); |
| 321 |
$this->setChroot(array($rootDir)); |
| 322 |
$this->setRootDir($rootDir); |
| 323 |
$this->setTempDir(\sys_get_temp_dir()); |
| 324 |
$this->setFontDir($rootDir . "/lib/fonts"); |
| 325 |
$this->setFontCache($this->getFontDir()); |
| 326 |
$ver = ""; |
| 327 |
$versionFile = \realpath(__DIR__ . '/../VERSION'); |
| 328 |
if (\file_exists($versionFile) && ($version = \file_get_contents($versionFile)) !== \false) { |
| 329 |
$version = \trim($version); |
| 330 |
if ($version !== '$Format:<%h>$') { |
| 331 |
$ver = "/{$version}"; |
| 332 |
} |
| 333 |
} |
| 334 |
$this->setHttpContext(["http" => ["follow_location" => \false, "user_agent" => "Dompdf{$ver} https://github.com/dompdf/dompdf"]]); |
| 335 |
$this->setAllowedProtocols(["data://", "file://", "http://", "https://"]); |
| 336 |
$this->setArtifactPathValidation([$this, "validateArtifactPath"]); |
| 337 |
// Get the memory limit |
| 338 |
$memory_limit = \ini_get('memory_limit'); |
| 339 |
$this->setImageByteSizeLimit($memory_limit); |
| 340 |
if (null !== $attributes) { |
| 341 |
$this->set($attributes); |
| 342 |
} |
| 343 |
} |
| 344 |
/** |
| 345 |
* @param array|string $attributes |
| 346 |
* @param null|mixed $value |
| 347 |
* @return $this |
| 348 |
*/ |
| 349 |
public function set($attributes, $value = null) |
| 350 |
{ |
| 351 |
if (!\is_array($attributes)) { |
| 352 |
$attributes = [$attributes => $value]; |
| 353 |
} |
| 354 |
foreach ($attributes as $key => $value) { |
| 355 |
$methodForMatch = \lcfirst(\str_replace(' ', '', \ucwords(\str_replace('_', ' ', $key)))); |
| 356 |
$methodForCall = "set" . \ucfirst($methodForMatch); |
| 357 |
if ($methodForMatch === 'enablePhp') { |
| 358 |
$methodForCall = "setIsPhpEnabled"; |
| 359 |
} elseif ($methodForMatch === 'enableRemote') { |
| 360 |
$methodForCall = "setIsRemoteEnabled"; |
| 361 |
} elseif ($methodForMatch === 'enablePdfA') { |
| 362 |
$methodForCall = "setIsPdfAEnabled"; |
| 363 |
} elseif ($methodForMatch === 'enableJavascript') { |
| 364 |
$methodForCall = "setIsJavascriptEnabled"; |
| 365 |
} elseif ($methodForMatch === 'enableHtml5Parser') { |
| 366 |
$methodForCall = "setIsHtml5ParserEnabled"; |
| 367 |
} elseif ($methodForMatch === 'enableFontSubsetting') { |
| 368 |
$methodForCall = "setIsFontSubsettingEnabled"; |
| 369 |
} |
| 370 |
if (\method_exists($this, $methodForCall)) { |
| 371 |
$this->{$methodForCall}($value); |
| 372 |
} |
| 373 |
} |
| 374 |
return $this; |
| 375 |
} |
| 376 |
/** |
| 377 |
* @param string $key |
| 378 |
* @return mixed |
| 379 |
*/ |
| 380 |
public function get($key) |
| 381 |
{ |
| 382 |
$methodForMatch = \lcfirst(\str_replace(' ', '', \ucwords(\str_replace('_', ' ', $key)))); |
| 383 |
$methodForCall = "get" . \ucfirst($methodForMatch); |
| 384 |
if ($methodForMatch === 'enablePhp') { |
| 385 |
$methodForCall = "getIsPhpEnabled"; |
| 386 |
} elseif ($methodForMatch === 'enableRemote') { |
| 387 |
$methodForCall = "getIsRemoteEnabled"; |
| 388 |
} elseif ($methodForMatch === 'enablePdfA') { |
| 389 |
$methodForCall = "getIsPdfAEnabled"; |
| 390 |
} elseif ($methodForMatch === 'enableJavascript') { |
| 391 |
$methodForCall = "getIsJavascriptEnabled"; |
| 392 |
} elseif ($methodForMatch === 'enableHtml5Parser') { |
| 393 |
$methodForCall = "getIsHtml5ParserEnabled"; |
| 394 |
} elseif ($methodForMatch === 'enableFontSubsetting') { |
| 395 |
$methodForCall = "getIsFontSubsettingEnabled"; |
| 396 |
} |
| 397 |
if (\method_exists($this, $methodForCall)) { |
| 398 |
return $this->{$methodForCall}(); |
| 399 |
} |
| 400 |
return null; |
| 401 |
} |
| 402 |
/** |
| 403 |
* @param string $pdfBackend |
| 404 |
* @return $this |
| 405 |
*/ |
| 406 |
public function setPdfBackend($pdfBackend) |
| 407 |
{ |
| 408 |
$this->pdfBackend = $pdfBackend; |
| 409 |
return $this; |
| 410 |
} |
| 411 |
/** |
| 412 |
* @return string |
| 413 |
*/ |
| 414 |
public function getPdfBackend() |
| 415 |
{ |
| 416 |
return $this->pdfBackend; |
| 417 |
} |
| 418 |
/** |
| 419 |
* @param string $pdflibLicense |
| 420 |
* @return $this |
| 421 |
*/ |
| 422 |
public function setPdflibLicense($pdflibLicense) |
| 423 |
{ |
| 424 |
$this->pdflibLicense = $pdflibLicense; |
| 425 |
return $this; |
| 426 |
} |
| 427 |
/** |
| 428 |
* @return string |
| 429 |
*/ |
| 430 |
public function getPdflibLicense() |
| 431 |
{ |
| 432 |
return $this->pdflibLicense; |
| 433 |
} |
| 434 |
/** |
| 435 |
* @param array|string $chroot |
| 436 |
* @return $this |
| 437 |
*/ |
| 438 |
public function setChroot($chroot, $delimiter = ',') |
| 439 |
{ |
| 440 |
if (\is_string($chroot)) { |
| 441 |
$this->chroot = \explode($delimiter, $chroot); |
| 442 |
} elseif (\is_array($chroot)) { |
| 443 |
$this->chroot = $chroot; |
| 444 |
} |
| 445 |
return $this; |
| 446 |
} |
| 447 |
/** |
| 448 |
* @return array |
| 449 |
*/ |
| 450 |
public function getAllowedProtocols() |
| 451 |
{ |
| 452 |
return $this->allowedProtocols; |
| 453 |
} |
| 454 |
/** |
| 455 |
* @param array $allowedProtocols The protocols to allow, as an array |
| 456 |
* formatted as ["protocol://" => ["rules" => [callable]], ...] |
| 457 |
* or ["protocol://", ...] |
| 458 |
* |
| 459 |
* @return $this |
| 460 |
*/ |
| 461 |
public function setAllowedProtocols(array $allowedProtocols) |
| 462 |
{ |
| 463 |
$protocols = []; |
| 464 |
foreach ($allowedProtocols as $protocol => $config) { |
| 465 |
if (\is_string($protocol)) { |
| 466 |
$protocols[$protocol] = []; |
| 467 |
if (\is_array($config)) { |
| 468 |
$protocols[$protocol] = $config; |
| 469 |
} |
| 470 |
} elseif (\is_string($config)) { |
| 471 |
$protocols[$config] = []; |
| 472 |
} |
| 473 |
} |
| 474 |
$this->allowedProtocols = []; |
| 475 |
foreach ($protocols as $protocol => $config) { |
| 476 |
$this->addAllowedProtocol($protocol, ...$config["rules"] ?? []); |
| 477 |
} |
| 478 |
return $this; |
| 479 |
} |
| 480 |
/** |
| 481 |
* Adds a new protocol to the allowed protocols collection |
| 482 |
* |
| 483 |
* @param string $protocol The scheme to add (e.g. "http://") |
| 484 |
* @param callable $rule A callable that validates the protocol |
| 485 |
* @return $this |
| 486 |
*/ |
| 487 |
public function addAllowedProtocol(string $protocol, callable ...$rules) |
| 488 |
{ |
| 489 |
$protocol = \strtolower($protocol); |
| 490 |
if (empty($rules)) { |
| 491 |
$rules = []; |
| 492 |
switch ($protocol) { |
| 493 |
case "data://": |
| 494 |
break; |
| 495 |
case "file://": |
| 496 |
$rules[] = [$this, "validateLocalUri"]; |
| 497 |
break; |
| 498 |
case "http://": |
| 499 |
case "https://": |
| 500 |
$rules[] = [$this, "validateRemoteUri"]; |
| 501 |
break; |
| 502 |
case "phar://": |
| 503 |
$rules[] = [$this, "validatePharUri"]; |
| 504 |
break; |
| 505 |
} |
| 506 |
} |
| 507 |
$this->allowedProtocols[$protocol] = ["rules" => $rules]; |
| 508 |
return $this; |
| 509 |
} |
| 510 |
/** |
| 511 |
* @return array |
| 512 |
*/ |
| 513 |
public function getArtifactPathValidation() |
| 514 |
{ |
| 515 |
return $this->artifactPathValidation; |
| 516 |
} |
| 517 |
/** |
| 518 |
* @param callable $validator |
| 519 |
* @return $this |
| 520 |
*/ |
| 521 |
public function setArtifactPathValidation($validator) |
| 522 |
{ |
| 523 |
$this->artifactPathValidation = $validator; |
| 524 |
return $this; |
| 525 |
} |
| 526 |
/** |
| 527 |
* @return array |
| 528 |
*/ |
| 529 |
public function getChroot() |
| 530 |
{ |
| 531 |
$chroot = []; |
| 532 |
if (\is_array($this->chroot)) { |
| 533 |
$chroot = $this->chroot; |
| 534 |
} |
| 535 |
return $chroot; |
| 536 |
} |
| 537 |
/** |
| 538 |
* @param boolean $debugCss |
| 539 |
* @return $this |
| 540 |
*/ |
| 541 |
public function setDebugCss($debugCss) |
| 542 |
{ |
| 543 |
$this->debugCss = $debugCss; |
| 544 |
return $this; |
| 545 |
} |
| 546 |
/** |
| 547 |
* @return boolean |
| 548 |
*/ |
| 549 |
public function getDebugCss() |
| 550 |
{ |
| 551 |
return $this->debugCss; |
| 552 |
} |
| 553 |
/** |
| 554 |
* @param boolean $debugKeepTemp |
| 555 |
* @return $this |
| 556 |
*/ |
| 557 |
public function setDebugKeepTemp($debugKeepTemp) |
| 558 |
{ |
| 559 |
$this->debugKeepTemp = $debugKeepTemp; |
| 560 |
return $this; |
| 561 |
} |
| 562 |
/** |
| 563 |
* @return boolean |
| 564 |
*/ |
| 565 |
public function getDebugKeepTemp() |
| 566 |
{ |
| 567 |
return $this->debugKeepTemp; |
| 568 |
} |
| 569 |
/** |
| 570 |
* @param boolean $debugLayout |
| 571 |
* @return $this |
| 572 |
*/ |
| 573 |
public function setDebugLayout($debugLayout) |
| 574 |
{ |
| 575 |
$this->debugLayout = $debugLayout; |
| 576 |
return $this; |
| 577 |
} |
| 578 |
/** |
| 579 |
* @return boolean |
| 580 |
*/ |
| 581 |
public function getDebugLayout() |
| 582 |
{ |
| 583 |
return $this->debugLayout; |
| 584 |
} |
| 585 |
/** |
| 586 |
* @param boolean $debugLayoutBlocks |
| 587 |
* @return $this |
| 588 |
*/ |
| 589 |
public function setDebugLayoutBlocks($debugLayoutBlocks) |
| 590 |
{ |
| 591 |
$this->debugLayoutBlocks = $debugLayoutBlocks; |
| 592 |
return $this; |
| 593 |
} |
| 594 |
/** |
| 595 |
* @return boolean |
| 596 |
*/ |
| 597 |
public function getDebugLayoutBlocks() |
| 598 |
{ |
| 599 |
return $this->debugLayoutBlocks; |
| 600 |
} |
| 601 |
/** |
| 602 |
* @param boolean $debugLayoutInline |
| 603 |
* @return $this |
| 604 |
*/ |
| 605 |
public function setDebugLayoutInline($debugLayoutInline) |
| 606 |
{ |
| 607 |
$this->debugLayoutInline = $debugLayoutInline; |
| 608 |
return $this; |
| 609 |
} |
| 610 |
/** |
| 611 |
* @return boolean |
| 612 |
*/ |
| 613 |
public function getDebugLayoutInline() |
| 614 |
{ |
| 615 |
return $this->debugLayoutInline; |
| 616 |
} |
| 617 |
/** |
| 618 |
* @param boolean $debugLayoutLines |
| 619 |
* @return $this |
| 620 |
*/ |
| 621 |
public function setDebugLayoutLines($debugLayoutLines) |
| 622 |
{ |
| 623 |
$this->debugLayoutLines = $debugLayoutLines; |
| 624 |
return $this; |
| 625 |
} |
| 626 |
/** |
| 627 |
* @return boolean |
| 628 |
*/ |
| 629 |
public function getDebugLayoutLines() |
| 630 |
{ |
| 631 |
return $this->debugLayoutLines; |
| 632 |
} |
| 633 |
/** |
| 634 |
* @param boolean $debugLayoutPaddingBox |
| 635 |
* @return $this |
| 636 |
*/ |
| 637 |
public function setDebugLayoutPaddingBox($debugLayoutPaddingBox) |
| 638 |
{ |
| 639 |
$this->debugLayoutPaddingBox = $debugLayoutPaddingBox; |
| 640 |
return $this; |
| 641 |
} |
| 642 |
/** |
| 643 |
* @return boolean |
| 644 |
*/ |
| 645 |
public function getDebugLayoutPaddingBox() |
| 646 |
{ |
| 647 |
return $this->debugLayoutPaddingBox; |
| 648 |
} |
| 649 |
/** |
| 650 |
* @param boolean $debugPng |
| 651 |
* @return $this |
| 652 |
*/ |
| 653 |
public function setDebugPng($debugPng) |
| 654 |
{ |
| 655 |
$this->debugPng = $debugPng; |
| 656 |
return $this; |
| 657 |
} |
| 658 |
/** |
| 659 |
* @return boolean |
| 660 |
*/ |
| 661 |
public function getDebugPng() |
| 662 |
{ |
| 663 |
return $this->debugPng; |
| 664 |
} |
| 665 |
/** |
| 666 |
* @param string $defaultFont |
| 667 |
* @return $this |
| 668 |
*/ |
| 669 |
public function setDefaultFont($defaultFont) |
| 670 |
{ |
| 671 |
if (!($defaultFont === null || \trim($defaultFont) === "")) { |
| 672 |
$this->defaultFont = $defaultFont; |
| 673 |
} else { |
| 674 |
$this->defaultFont = "serif"; |
| 675 |
} |
| 676 |
return $this; |
| 677 |
} |
| 678 |
/** |
| 679 |
* @return string |
| 680 |
*/ |
| 681 |
public function getDefaultFont() |
| 682 |
{ |
| 683 |
return $this->defaultFont; |
| 684 |
} |
| 685 |
/** |
| 686 |
* @param string $defaultMediaType |
| 687 |
* @return $this |
| 688 |
*/ |
| 689 |
public function setDefaultMediaType($defaultMediaType) |
| 690 |
{ |
| 691 |
$this->defaultMediaType = $defaultMediaType; |
| 692 |
return $this; |
| 693 |
} |
| 694 |
/** |
| 695 |
* @return string |
| 696 |
*/ |
| 697 |
public function getDefaultMediaType() |
| 698 |
{ |
| 699 |
return $this->defaultMediaType; |
| 700 |
} |
| 701 |
/** |
| 702 |
* @param string|float[] $defaultPaperSize |
| 703 |
* @return $this |
| 704 |
*/ |
| 705 |
public function setDefaultPaperSize($defaultPaperSize) : self |
| 706 |
{ |
| 707 |
$this->defaultPaperSize = $defaultPaperSize; |
| 708 |
return $this; |
| 709 |
} |
| 710 |
/** |
| 711 |
* @param string $defaultPaperOrientation |
| 712 |
* @return $this |
| 713 |
*/ |
| 714 |
public function setDefaultPaperOrientation(string $defaultPaperOrientation) : self |
| 715 |
{ |
| 716 |
$this->defaultPaperOrientation = $defaultPaperOrientation; |
| 717 |
return $this; |
| 718 |
} |
| 719 |
/** |
| 720 |
* @return string|float[] |
| 721 |
*/ |
| 722 |
public function getDefaultPaperSize() |
| 723 |
{ |
| 724 |
return $this->defaultPaperSize; |
| 725 |
} |
| 726 |
/** |
| 727 |
* @return string |
| 728 |
*/ |
| 729 |
public function getDefaultPaperOrientation() : string |
| 730 |
{ |
| 731 |
return $this->defaultPaperOrientation; |
| 732 |
} |
| 733 |
/** |
| 734 |
* @param int $dpi |
| 735 |
* @return $this |
| 736 |
*/ |
| 737 |
public function setDpi($dpi) |
| 738 |
{ |
| 739 |
$this->dpi = $dpi; |
| 740 |
return $this; |
| 741 |
} |
| 742 |
/** |
| 743 |
* @return int |
| 744 |
*/ |
| 745 |
public function getDpi() |
| 746 |
{ |
| 747 |
return $this->dpi; |
| 748 |
} |
| 749 |
/** |
| 750 |
* @param string $fontCache |
| 751 |
* @return $this |
| 752 |
*/ |
| 753 |
public function setFontCache($fontCache) |
| 754 |
{ |
| 755 |
if (!\is_callable($this->artifactPathValidation) || ($this->artifactPathValidation)($fontCache, "fontCache") === \true) { |
| 756 |
$this->fontCache = $fontCache; |
| 757 |
} |
| 758 |
return $this; |
| 759 |
} |
| 760 |
/** |
| 761 |
* @return string |
| 762 |
*/ |
| 763 |
public function getFontCache() |
| 764 |
{ |
| 765 |
return $this->fontCache; |
| 766 |
} |
| 767 |
/** |
| 768 |
* @param string $fontDir |
| 769 |
* @return $this |
| 770 |
*/ |
| 771 |
public function setFontDir($fontDir) |
| 772 |
{ |
| 773 |
if (!\is_callable($this->artifactPathValidation) || ($this->artifactPathValidation)($fontDir, "fontDir") === \true) { |
| 774 |
$this->fontDir = $fontDir; |
| 775 |
} |
| 776 |
return $this; |
| 777 |
} |
| 778 |
/** |
| 779 |
* @return string |
| 780 |
*/ |
| 781 |
public function getFontDir() |
| 782 |
{ |
| 783 |
return $this->fontDir; |
| 784 |
} |
| 785 |
/** |
| 786 |
* @param float $fontHeightRatio |
| 787 |
* @return $this |
| 788 |
*/ |
| 789 |
public function setFontHeightRatio($fontHeightRatio) |
| 790 |
{ |
| 791 |
$this->fontHeightRatio = $fontHeightRatio; |
| 792 |
return $this; |
| 793 |
} |
| 794 |
/** |
| 795 |
* @return float |
| 796 |
*/ |
| 797 |
public function getFontHeightRatio() |
| 798 |
{ |
| 799 |
return $this->fontHeightRatio; |
| 800 |
} |
| 801 |
/** |
| 802 |
* @param int $imageMemoryLimit |
| 803 |
* @return $this |
| 804 |
*/ |
| 805 |
public function setImageByteSizeLimit($imageByteSizeLimit) |
| 806 |
{ |
| 807 |
// Convert shorthand notation to bytes |
| 808 |
if (\preg_match('/^(\\d+)([KMG])$/i', $imageByteSizeLimit, $matches)) { |
| 809 |
if (\strtoupper($matches[2]) == 'K') { |
| 810 |
$imageByteSizeLimit = (int) $matches[1] * 1024; |
| 811 |
} elseif (\strtoupper($matches[2]) == 'M') { |
| 812 |
$imageByteSizeLimit = (int) $matches[1] * 1024 * 1024; |
| 813 |
} elseif (\strtoupper($matches[2]) == 'G') { |
| 814 |
$imageByteSizeLimit = (int) $matches[1] * 1024 * 1024 * 1024; |
| 815 |
} |
| 816 |
} |
| 817 |
if (\is_numeric($imageByteSizeLimit)) { |
| 818 |
$this->imageByteSizeLimit = $imageByteSizeLimit > 0 ? $imageByteSizeLimit : -1; |
| 819 |
} |
| 820 |
return $this; |
| 821 |
} |
| 822 |
/** |
| 823 |
* @return int |
| 824 |
*/ |
| 825 |
public function getImageByteSizeLimit() |
| 826 |
{ |
| 827 |
return $this->imageByteSizeLimit; |
| 828 |
} |
| 829 |
/** |
| 830 |
* @param boolean $isFontSubsettingEnabled |
| 831 |
* @return $this |
| 832 |
*/ |
| 833 |
public function setIsFontSubsettingEnabled($isFontSubsettingEnabled) |
| 834 |
{ |
| 835 |
$this->isFontSubsettingEnabled = $isFontSubsettingEnabled; |
| 836 |
return $this; |
| 837 |
} |
| 838 |
/** |
| 839 |
* @return boolean |
| 840 |
*/ |
| 841 |
public function getIsFontSubsettingEnabled() |
| 842 |
{ |
| 843 |
return $this->isFontSubsettingEnabled; |
| 844 |
} |
| 845 |
/** |
| 846 |
* @return boolean |
| 847 |
*/ |
| 848 |
public function isFontSubsettingEnabled() |
| 849 |
{ |
| 850 |
return $this->getIsFontSubsettingEnabled(); |
| 851 |
} |
| 852 |
/** |
| 853 |
* @deprecated |
| 854 |
* @param boolean $isHtml5ParserEnabled |
| 855 |
* @return $this |
| 856 |
*/ |
| 857 |
public function setIsHtml5ParserEnabled($isHtml5ParserEnabled) |
| 858 |
{ |
| 859 |
$this->isHtml5ParserEnabled = $isHtml5ParserEnabled; |
| 860 |
return $this; |
| 861 |
} |
| 862 |
/** |
| 863 |
* @deprecated |
| 864 |
* @return boolean |
| 865 |
*/ |
| 866 |
public function getIsHtml5ParserEnabled() |
| 867 |
{ |
| 868 |
return $this->isHtml5ParserEnabled; |
| 869 |
} |
| 870 |
/** |
| 871 |
* @deprecated |
| 872 |
* @return boolean |
| 873 |
*/ |
| 874 |
public function isHtml5ParserEnabled() |
| 875 |
{ |
| 876 |
return $this->getIsHtml5ParserEnabled(); |
| 877 |
} |
| 878 |
/** |
| 879 |
* @param boolean $isJavascriptEnabled |
| 880 |
* @return $this |
| 881 |
*/ |
| 882 |
public function setIsJavascriptEnabled($isJavascriptEnabled) |
| 883 |
{ |
| 884 |
$this->isJavascriptEnabled = $isJavascriptEnabled; |
| 885 |
return $this; |
| 886 |
} |
| 887 |
/** |
| 888 |
* @return boolean |
| 889 |
*/ |
| 890 |
public function getIsJavascriptEnabled() |
| 891 |
{ |
| 892 |
return $this->isJavascriptEnabled; |
| 893 |
} |
| 894 |
/** |
| 895 |
* @return boolean |
| 896 |
*/ |
| 897 |
public function isJavascriptEnabled() |
| 898 |
{ |
| 899 |
return $this->getIsJavascriptEnabled(); |
| 900 |
} |
| 901 |
/** |
| 902 |
* @param boolean $isPhpEnabled |
| 903 |
* @return $this |
| 904 |
*/ |
| 905 |
public function setIsPhpEnabled($isPhpEnabled) |
| 906 |
{ |
| 907 |
$this->isPhpEnabled = $isPhpEnabled; |
| 908 |
return $this; |
| 909 |
} |
| 910 |
/** |
| 911 |
* @return boolean |
| 912 |
*/ |
| 913 |
public function getIsPhpEnabled() |
| 914 |
{ |
| 915 |
return $this->isPhpEnabled; |
| 916 |
} |
| 917 |
/** |
| 918 |
* @return boolean |
| 919 |
*/ |
| 920 |
public function isPhpEnabled() |
| 921 |
{ |
| 922 |
return $this->getIsPhpEnabled(); |
| 923 |
} |
| 924 |
/** |
| 925 |
* @param boolean $isRemoteEnabled |
| 926 |
* @return $this |
| 927 |
*/ |
| 928 |
public function setIsRemoteEnabled($isRemoteEnabled) |
| 929 |
{ |
| 930 |
$this->isRemoteEnabled = $isRemoteEnabled; |
| 931 |
return $this; |
| 932 |
} |
| 933 |
/** |
| 934 |
* @return boolean |
| 935 |
*/ |
| 936 |
public function getIsRemoteEnabled() |
| 937 |
{ |
| 938 |
return $this->isRemoteEnabled; |
| 939 |
} |
| 940 |
/** |
| 941 |
* @return boolean |
| 942 |
*/ |
| 943 |
public function isRemoteEnabled() |
| 944 |
{ |
| 945 |
return $this->getIsRemoteEnabled(); |
| 946 |
} |
| 947 |
/** |
| 948 |
* @param array|null $allowedRemoteHosts |
| 949 |
* @return $this |
| 950 |
*/ |
| 951 |
public function setAllowedRemoteHosts($allowedRemoteHosts) |
| 952 |
{ |
| 953 |
if (\is_array($allowedRemoteHosts)) { |
| 954 |
// Set hosts to lowercase |
| 955 |
foreach ($allowedRemoteHosts as &$host) { |
| 956 |
$host = \mb_strtolower($host, "UTF-8"); |
| 957 |
} |
| 958 |
unset($host); |
| 959 |
} |
| 960 |
$this->allowedRemoteHosts = $allowedRemoteHosts; |
| 961 |
return $this; |
| 962 |
} |
| 963 |
/** |
| 964 |
* @return array|null |
| 965 |
*/ |
| 966 |
public function getAllowedRemoteHosts() |
| 967 |
{ |
| 968 |
return $this->allowedRemoteHosts; |
| 969 |
} |
| 970 |
/** |
| 971 |
* @param boolean $isRemoteEnabled |
| 972 |
* @return $this |
| 973 |
*/ |
| 974 |
public function setIsPdfAEnabled($isPdfAEnabled) |
| 975 |
{ |
| 976 |
$this->isPdfAEnabled = $isPdfAEnabled; |
| 977 |
return $this; |
| 978 |
} |
| 979 |
/** |
| 980 |
* @return boolean |
| 981 |
*/ |
| 982 |
public function getIsPdfAEnabled() |
| 983 |
{ |
| 984 |
return $this->isPdfAEnabled; |
| 985 |
} |
| 986 |
/** |
| 987 |
* @return boolean |
| 988 |
*/ |
| 989 |
public function isPdfAEnabled() |
| 990 |
{ |
| 991 |
return $this->getIsPdfAEnabled(); |
| 992 |
} |
| 993 |
/** |
| 994 |
* @param string $logOutputFile |
| 995 |
* @return $this |
| 996 |
*/ |
| 997 |
public function setLogOutputFile($logOutputFile) |
| 998 |
{ |
| 999 |
if (!\is_callable($this->artifactPathValidation) || ($this->artifactPathValidation)($logOutputFile, "logOutputFile") === \true) { |
| 1000 |
$this->logOutputFile = $logOutputFile; |
| 1001 |
} |
| 1002 |
return $this; |
| 1003 |
} |
| 1004 |
/** |
| 1005 |
* @return string |
| 1006 |
*/ |
| 1007 |
public function getLogOutputFile() |
| 1008 |
{ |
| 1009 |
return $this->logOutputFile; |
| 1010 |
} |
| 1011 |
/** |
| 1012 |
* @param string $tempDir |
| 1013 |
* @return $this |
| 1014 |
*/ |
| 1015 |
public function setTempDir($tempDir) |
| 1016 |
{ |
| 1017 |
if (!\is_callable($this->artifactPathValidation) || ($this->artifactPathValidation)($tempDir, "tempDir") === \true) { |
| 1018 |
$this->tempDir = $tempDir; |
| 1019 |
} |
| 1020 |
return $this; |
| 1021 |
} |
| 1022 |
/** |
| 1023 |
* @return string |
| 1024 |
*/ |
| 1025 |
public function getTempDir() |
| 1026 |
{ |
| 1027 |
return $this->tempDir; |
| 1028 |
} |
| 1029 |
/** |
| 1030 |
* @param string $rootDir |
| 1031 |
* @return $this |
| 1032 |
*/ |
| 1033 |
public function setRootDir($rootDir) |
| 1034 |
{ |
| 1035 |
if (!\is_callable($this->artifactPathValidation) || ($this->artifactPathValidation)($rootDir, "rootDir") === \true) { |
| 1036 |
$this->rootDir = $rootDir; |
| 1037 |
} |
| 1038 |
return $this; |
| 1039 |
} |
| 1040 |
/** |
| 1041 |
* @return string |
| 1042 |
*/ |
| 1043 |
public function getRootDir() |
| 1044 |
{ |
| 1045 |
return $this->rootDir; |
| 1046 |
} |
| 1047 |
/** |
| 1048 |
* Sets the HTTP context |
| 1049 |
* |
| 1050 |
* @param resource|array $httpContext |
| 1051 |
* @return $this |
| 1052 |
*/ |
| 1053 |
public function setHttpContext($httpContext) |
| 1054 |
{ |
| 1055 |
$this->httpContext = \is_array($httpContext) ? \stream_context_create($httpContext) : $httpContext; |
| 1056 |
return $this; |
| 1057 |
} |
| 1058 |
/** |
| 1059 |
* Returns the HTTP context |
| 1060 |
* |
| 1061 |
* @return resource |
| 1062 |
*/ |
| 1063 |
public function getHttpContext() |
| 1064 |
{ |
| 1065 |
return $this->httpContext; |
| 1066 |
} |
| 1067 |
public function validateArtifactPath(?string $path, string $option) |
| 1068 |
{ |
| 1069 |
if ($path === null) { |
| 1070 |
return \true; |
| 1071 |
} |
| 1072 |
$parsed_uri = \parse_url($path); |
| 1073 |
if ($parsed_uri === \false || \array_key_exists("scheme", $parsed_uri) && \strtolower($parsed_uri["scheme"]) === "phar") { |
| 1074 |
return \false; |
| 1075 |
} |
| 1076 |
return \true; |
| 1077 |
} |
| 1078 |
public function validateLocalUri(string $uri) |
| 1079 |
{ |
| 1080 |
if ($uri === null || \strlen($uri) === 0) { |
| 1081 |
return [\false, "The URI must not be empty."]; |
| 1082 |
} |
| 1083 |
$realfile = \realpath(\str_replace("file://", "", $uri)); |
| 1084 |
if ($realfile === \false) { |
| 1085 |
return [\false, "File not found."]; |
| 1086 |
} |
| 1087 |
$dirs = $this->chroot; |
| 1088 |
$dirs[] = $this->rootDir; |
| 1089 |
$chrootValid = \false; |
| 1090 |
foreach ($dirs as $chrootPath) { |
| 1091 |
$chrootPath = \realpath($chrootPath); |
| 1092 |
if ($chrootPath === \false) { |
| 1093 |
continue; |
| 1094 |
} |
| 1095 |
$normalizedChrootPath = \rtrim($chrootPath, \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR; |
| 1096 |
if ($realfile === $chrootPath || \strncmp($realfile, $normalizedChrootPath, \strlen($normalizedChrootPath)) === 0) { |
| 1097 |
$chrootValid = \true; |
| 1098 |
break; |
| 1099 |
} |
| 1100 |
} |
| 1101 |
if ($chrootValid !== \true) { |
| 1102 |
return [\false, "Permission denied. The file could not be found under the paths specified by Options::chroot."]; |
| 1103 |
} |
| 1104 |
return [\true, null]; |
| 1105 |
} |
| 1106 |
public function validatePharUri(string $uri) |
| 1107 |
{ |
| 1108 |
if ($uri === null || \strlen($uri) === 0) { |
| 1109 |
return [\false, "The URI must not be empty."]; |
| 1110 |
} |
| 1111 |
$file = \substr(\substr($uri, 0, \strpos($uri, ".phar") + 5), 7); |
| 1112 |
return $this->validateLocalUri($file); |
| 1113 |
} |
| 1114 |
public function validateRemoteUri(string $uri) |
| 1115 |
{ |
| 1116 |
if ($uri === null || \strlen($uri) === 0) { |
| 1117 |
return [\false, "The URI must not be empty."]; |
| 1118 |
} |
| 1119 |
if (!$this->isRemoteEnabled) { |
| 1120 |
return [\false, "Remote file requested, but remote file download is disabled."]; |
| 1121 |
} |
| 1122 |
if (\is_array($this->allowedRemoteHosts) && \count($this->allowedRemoteHosts) > 0) { |
| 1123 |
$host = \parse_url($uri, \PHP_URL_HOST); |
| 1124 |
$host = \mb_strtolower($host, "UTF-8"); |
| 1125 |
if (!\in_array($host, $this->allowedRemoteHosts, \true)) { |
| 1126 |
return [\false, "Remote host is not in allowed list: " . $host]; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
return [\true, null]; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|