Skip to content

Commit ea32973

Browse files
committed
actually handle booleans
1 parent 9e07491 commit ea32973

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/PDF.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PDF
2121
'bottom' => 0,
2222
'left' => 0,
2323
),
24-
'printBackground' => 'true', //override binary default
24+
'printBackground' => true, //override binary default
2525
);
2626

2727
/**
@@ -87,14 +87,14 @@ public function __construct(string $pathtobinary = 'chrome-pdf')
8787
*
8888
* @param array $options a reference to an existing array of options
8989
* @param string $name the name of the option to apply
90-
* @param string $value the input value
90+
* @param string|bool $value the input value
9191
*
9292
* @throws InvalidOptionException
9393
* @throws InvalidValueException
9494
*
9595
* @return void
9696
*/
97-
protected function addOption(array &$options, string $name, string $value) : void
97+
protected function addOption(array &$options, string $name, $value) : void
9898
{
9999
if (in_array($name, $this->possibleoptions)) {
100100
if ($name == 'margin') {
@@ -160,11 +160,11 @@ protected function addOption(array &$options, string $name, string $value) : voi
160160
* Public interface to addOption function
161161
*
162162
* @param string $name the name of the option to apply
163-
* @param string $value the input value
163+
* @param string|bool $value the input value
164164
*
165165
* @return self allows chaining
166166
*/
167-
public function setOption(string $name, string $value) : self
167+
public function setOption(string $name, $value) : self
168168
{
169169
$this->addOption($this->options, $name, $value);
170170

@@ -337,7 +337,7 @@ private function make(array $options) : string
337337
foreach ($options as $option => $value) {
338338
if ($option == 'sandbox') {
339339
// only mess with sandbox if it is explicitly disabled
340-
if ($value == 'false') {
340+
if ($value === false) {
341341
$command[] = '--no-sandbox';
342342
}
343343

@@ -357,7 +357,18 @@ private function make(array $options) : string
357357
}
358358

359359
$command[] = '--' . $option;
360-
$command[] = (is_array($value)) ? implode(',', $value) : $value;
360+
361+
if (is_array($value)) {
362+
$command[] = implode(',', $value);
363+
continue;
364+
} elseif ($value === true || $value === false) {
365+
$command[] = var_export($value, true);
366+
continue;
367+
} elseif (! is_string($value)) {
368+
throw new InvalidValueException;
369+
}
370+
371+
$command[] = $value;
361372
}
362373

363374
$process = new Process($command);

src/SnappyPDF.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class SnappyPDF extends PDF
3131
'orientation' => array(
3232
'mapto' => 'landscape',
3333
'boolean' => array(
34-
'landscape' => 'true',
35-
'portrait' => 'false',
36-
'Landscape' => 'true',
37-
'Portrait' => 'false',
34+
'landscape' => true,
35+
'portrait' => false,
36+
'Landscape' => true,
37+
'Portrait' => false,
3838
),
3939
),
4040
'viewport-size' => array(
@@ -50,13 +50,13 @@ class SnappyPDF extends PDF
5050
*
5151
* @param array $options a reference to an existing array of options
5252
* @param string $name the name of the option to apply
53-
* @param string $value the input value
53+
* @param string|bool $value the input value
5454
*
5555
* @throws InvalidArgumentException
5656
*
5757
* @return void
5858
*/
59-
protected function addOption(array &$options, string $name, string $value) : void
59+
protected function addOption(array &$options, string $name, $value) : void
6060
{
6161
if (array_key_exists($name, $this->snappyoptions)) {
6262
if (is_array($this->snappyoptions[$name])) {

0 commit comments

Comments
 (0)