13
13
*/
14
14
class JPEGService
15
15
{
16
- /**
17
- * @var string
18
- */
19
- private $ bin_path ;
20
-
21
- /**
22
- * @var string
23
- */
24
- private $ args ;
25
-
26
16
/**
27
17
* @param string|null $bin_path optional path to `jpeg-recompress` binary (defaults to a built-in binary)
28
18
* @param string $args command-line arguments for `jpeg-recompress`, with {INPUT} and {OUTPUT} placeholders
29
19
*/
30
- public function __construct (string $ bin_path = null , string $ args = "--min 50 {INPUT} {OUTPUT} " )
31
- {
20
+ public function __construct (
21
+ private ?string $ bin_path = null ,
22
+ private string $ args = "--min 50 {INPUT} {OUTPUT} "
23
+ ) {
32
24
if ($ bin_path === null ) {
33
25
$ bin_dir = dirname (__DIR__ ) . DIRECTORY_SEPARATOR . "bin " . DIRECTORY_SEPARATOR ;
34
26
35
27
if (strncasecmp (PHP_OS , "LINUX " , 5 ) === 0 ) {
36
- $ bin_path = $ bin_dir . "linux " . DIRECTORY_SEPARATOR . "jpeg-recompress " ;
28
+ $ this -> bin_path = $ bin_dir . "linux " . DIRECTORY_SEPARATOR . "jpeg-recompress " ;
37
29
} elseif (strncasecmp (PHP_OS , "DARWIN " , 6 ) === 0 ) {
38
- $ bin_path = $ bin_dir . "mac " . DIRECTORY_SEPARATOR . "jpeg-recompress " ;
30
+ $ this -> bin_path = $ bin_dir . "mac " . DIRECTORY_SEPARATOR . "jpeg-recompress " ;
39
31
} elseif (strncasecmp (PHP_OS , "WIN " , 3 ) === 0 ) {
40
- $ bin_path = $ bin_dir . "win " . DIRECTORY_SEPARATOR . "jpeg-recompress.exe " ;
32
+ $ this -> bin_path = $ bin_dir . "win " . DIRECTORY_SEPARATOR . "jpeg-recompress.exe " ;
41
33
} else {
42
34
throw new RuntimeException ("unsupported OS: " . PHP_OS );
43
35
}
44
36
}
45
-
46
- $ this ->bin_path = $ bin_path ;
47
- $ this ->args = $ args ;
48
37
}
49
38
50
39
/**
@@ -55,7 +44,7 @@ public function __construct(string $bin_path = null, string $args = "--min 50 {I
55
44
*
56
45
* @throws ProcessFailedException on failure to execute the command-line tool
57
46
*/
58
- public function compress (string $ input , string $ output )
47
+ public function compress (string $ input , string $ output ): void
59
48
{
60
49
$ command = strtr (
61
50
"{$ this ->bin_path } {$ this ->args }" ,
0 commit comments