Skip to content

Commit dccea43

Browse files
committed
Format code and comments
1 parent bc47743 commit dccea43

File tree

3 files changed

+108
-83
lines changed

3 files changed

+108
-83
lines changed

src/Command.php

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/**
77
* Command
88
*
9-
* This class is an extension of mikehaertl\shellcommand\Command and adds
10-
* wk* specific features like xvfb support and proper argument handling.
9+
* This class is an extension of mikehaertl\shellcommand\Command and adds `wk*`
10+
* specific features like xvfb support and proper argument handling.
1111
*
1212
* @author Michael Härtl <[email protected]>
1313
* @license http://www.opensource.org/licenses/MIT
@@ -20,43 +20,47 @@ class Command extends BaseCommand
2020
public $enableXvfb = false;
2121

2222
/**
23-
* @var string the name of the xvfb-run comand. Default is `xvfb-run`.
24-
* You can also configure a full path here.
23+
* @var string the name of the xvfb-run comand. Default is `xvfb-run`. You
24+
* can also configure a full path here.
2525
*/
2626
public $xvfbRunBinary = 'xvfb-run';
2727

2828
/**
29-
* @var string options to pass to the xfvb-run command. Default is `--server-args="-screen 0, 1024x768x24"`.
29+
* @var string options to pass to the xfvb-run command. Default is
30+
* `--server-args="-screen 0, 1024x768x24"`.
3031
*/
3132
public $xvfbRunOptions = '-a --server-args="-screen 0, 1024x768x24"';
3233

3334
/**
3435
* @param array $args args to add to the command. These can be:
35-
* array(
36-
* // Special argument 'input' will not get prepended with '--'.
37-
* 'input' => 'cover',
36+
* ```
37+
* [
38+
* // Special argument 'input' will not get prepended with '--'.
39+
* 'input' => 'cover',
3840
*
39-
* // Special argument 'inputArg' is treated like 'input' but will get escaped
40-
* // Both 'input' and 'inputArg' can be used in combination
41-
* 'inputArg' => '/tmp/tmpFileName.html',
41+
* // Special argument 'inputArg' is treated like 'input' but will get escaped
42+
* // Both 'input' and 'inputArg' can be used in combination
43+
* 'inputArg' => '/tmp/tmpFileName.html',
4244
*
43-
* 'no-outline', // option without argument
44-
* 'encoding' => 'UTF-8', // option with argument
45+
* 'no-outline', // option without argument
46+
* 'encoding' => 'UTF-8', // option with argument
4547
*
46-
* // Option with 2 arguments
47-
* 'cookie' => array('name'=>'value'),
48+
* // Option with 2 arguments
49+
* 'cookie' => array('name'=>'value'),
4850
*
49-
* // Repeatable options with single argument
50-
* 'run-script' => array(
51-
* 'local1.js',
52-
* 'local2.js',
53-
* ),
51+
* // Repeatable options with single argument
52+
* 'run-script' => array(
53+
* 'local1.js',
54+
* 'local2.js',
55+
* ),
5456
*
55-
* // Repeatable options with 2 arguments
56-
* 'replace' => array(
57-
* '{page}' => $page++,
58-
* '{title}' => $pageTitle,
59-
* ),
57+
* // Repeatable options with 2 arguments
58+
* 'replace' => array(
59+
* '{page}' => $page++,
60+
* '{title}' => $pageTitle,
61+
* ),
62+
* ]
63+
* ```
6064
*/
6165
public function addArgs($args)
6266
{
@@ -70,7 +74,7 @@ public function addArgs($args)
7074
$this->addArg((string) $args['inputArg'], null, true);
7175
unset($args['inputArg']);
7276
}
73-
foreach($args as $key=>$val) {
77+
foreach($args as $key => $val) {
7478
if (is_numeric($key)) {
7579
$this->addArg("--$val");
7680
} elseif (is_array($val)) {
@@ -88,7 +92,8 @@ public function addArgs($args)
8892
}
8993

9094
/**
91-
* @return string|bool the command to execute with optional Xfvb wrapper applied. Null if none set.
95+
* @return string|bool the command to execute with optional Xfvb wrapper
96+
* applied. Null if none set.
9297
*/
9398
public function getExecCommand()
9499
{
@@ -99,4 +104,3 @@ public function getExecCommand()
99104
return $command;
100105
}
101106
}
102-

src/Image.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Pdf
88
*
9-
* This class is a slim wrapper around wkhtmltoimage.
9+
* This class is a slim wrapper around `wkhtmltoimage`.
1010
*
1111
* @author Michael Härtl <[email protected]>
1212
* @license http://www.opensource.org/licenses/MIT
@@ -20,13 +20,14 @@ class Image
2020
const TMP_PREFIX = 'tmp_wkhtmlto_pdf_';
2121

2222
/**
23-
* @var string the name of the `wkhtmltoimage` binary. Default is `wkhtmltoimage`. You can also
24-
* configure a full path here.
23+
* @var string the name of the `wkhtmltoimage` binary. Default is
24+
* `wkhtmltoimage`. You can also configure a full path here.
2525
*/
2626
public $binary = 'wkhtmltoimage';
2727

2828
/**
29-
* @var string the image type. Default is 'png'. Other options are 'jpg' and 'bmp'.
29+
* @var string the image type. Default is 'png'. Other options are 'jpg'
30+
* and 'bmp'.
3031
*/
3132
public $type = 'png';
3233

@@ -36,12 +37,14 @@ class Image
3637
public $commandOptions = array();
3738

3839
/**
39-
* @var string|null the directory to use for temporary files. If null (default) the dir is autodetected.
40+
* @var string|null the directory to use for temporary files. If `null`
41+
* (default) the dir is autodetected.
4042
*/
4143
public $tmpDir;
4244

4345
/**
44-
* @var bool whether to ignore any errors if some PDF file was still created. Default is false.
46+
* @var bool whether to ignore any errors if some PDF file was still
47+
* created. Default is `false`.
4548
*/
4649
public $ignoreWarnings = false;
4750

@@ -51,12 +54,14 @@ class Image
5154
protected $_isCreated = false;
5255

5356
/**
54-
* @var \mikehaertl\tmp\File|string the page input or a File instance for HTML string inputs
57+
* @var \mikehaertl\tmp\File|string the page input or a `File` instance for
58+
* HTML string inputs
5559
*/
5660
protected $_page;
5761

5862
/**
59-
* @var array options for wkhtmltoimage as array('--opt1', '--opt2'=>'val', ...)
63+
* @var array options for `wkhtmltoimage` as `['--opt1', '--opt2' => 'val',
64+
* ...]`
6065
*/
6166
protected $_options = array();
6267

@@ -76,9 +81,10 @@ class Image
7681
protected $_error = '';
7782

7883
/**
79-
* @param array|string $options global options for wkhtmltoimage, a page URL, a HTML string or a filename
84+
* @param array|string $options global options for wkhtmltoimage, a page
85+
* URL, a HTML string or a filename
8086
*/
81-
public function __construct($options=null)
87+
public function __construct($options = null)
8288
{
8389
if (is_array($options)) {
8490
$this->setOptions($options);
@@ -119,14 +125,17 @@ public function saveAs($filename)
119125
}
120126

121127
/**
122-
* Send image to client, either inline or as download (triggers image creation)
128+
* Send image to client, either inline or as download (triggers image
129+
* creation)
123130
*
124-
* @param string|null $filename the filename to send. If empty, the PDF is streamed inline. Note, that
125-
* the file extension must match what you configured as $type (png, jpg, ...).
126-
* @param bool $inline whether to force inline display of the image, even if filename is present.
131+
* @param string|null $filename the filename to send. If empty, the PDF is
132+
* streamed inline. Note, that the file extension must match what you
133+
* configured as $type (png, jpg, ...).
134+
* @param bool $inline whether to force inline display of the image, even
135+
* if filename is present.
127136
* @return bool whether image was created successfully
128137
*/
129-
public function send($filename=null,$inline=false)
138+
public function send($filename = null,$inline = false)
130139
{
131140
if (!$this->_isCreated && !$this->createImage()) {
132141
return false;
@@ -141,9 +150,9 @@ public function send($filename=null,$inline=false)
141150
* @param array $options list of image options to set as name/value pairs
142151
* @return static the Image instance for method chaining
143152
*/
144-
public function setOptions($options=array())
153+
public function setOptions($options = array())
145154
{
146-
foreach ($options as $key=>$val) {
155+
foreach ($options as $key => $val) {
147156
if (is_int($key)) {
148157
$this->_options[] = $val;
149158
} elseif ($key[0]!=='_' && property_exists($this, $key)) {
@@ -160,7 +169,7 @@ public function setOptions($options=array())
160169
*/
161170
public function getCommand()
162171
{
163-
if ($this->_command===null) {
172+
if ($this->_command === null) {
164173
$options = $this->commandOptions;
165174
if (!isset($options['command'])) {
166175
$options['command'] = $this->binary;
@@ -183,7 +192,7 @@ public function getError()
183192
*/
184193
public function getImageFilename()
185194
{
186-
if ($this->_tmpImageFile===null) {
195+
if ($this->_tmpImageFile === null) {
187196
$this->_tmpImageFile = new File('', '.'.$this->type, self::TMP_PREFIX);
188197
}
189198
return $this->_tmpImageFile->getFileName();
@@ -195,11 +204,11 @@ public function getImageFilename()
195204
*/
196205
public function getMimeType()
197206
{
198-
if ($this->type==='jpg') {
207+
if ($this->type === 'jpg') {
199208
return 'image/jpeg';
200-
} elseif ($this->type==='png') {
209+
} elseif ($this->type === 'png') {
201210
return 'image/png';
202-
} elseif ($this->type==='bmp') {
211+
} elseif ($this->type === 'bmp') {
203212
return 'image/bmp';
204213
} else {
205214
throw new \Exception('Invalid image type');

0 commit comments

Comments
 (0)