| 1 |
<?php |
| 2 |
|
| 3 |
namespace Spatie\ImageOptimizer\Optimizers; |
| 4 |
|
| 5 |
use Spatie\ImageOptimizer\Optimizer; |
| 6 |
|
| 7 |
abstract class BaseOptimizer implements Optimizer |
| 8 |
{ |
| 9 |
public $options = []; |
| 10 |
|
| 11 |
public $imagePath = ''; |
| 12 |
|
| 13 |
public $binaryPath = ''; |
| 14 |
|
| 15 |
public $tmpPath = null; |
| 16 |
|
| 17 |
public function __construct($options = []) |
| 18 |
{ |
| 19 |
$this->setOptions($options); |
| 20 |
} |
| 21 |
|
| 22 |
public function binaryName(): string |
| 23 |
{ |
| 24 |
return $this->binaryName; |
| 25 |
} |
| 26 |
|
| 27 |
public function setBinaryPath(string $binaryPath) |
| 28 |
{ |
| 29 |
if (strlen($binaryPath) > 0 && substr($binaryPath, -1) !== DIRECTORY_SEPARATOR) { |
| 30 |
$binaryPath = $binaryPath.DIRECTORY_SEPARATOR; |
| 31 |
} |
| 32 |
|
| 33 |
$this->binaryPath = $binaryPath; |
| 34 |
|
| 35 |
return $this; |
| 36 |
} |
| 37 |
|
| 38 |
public function setImagePath(string $imagePath) |
| 39 |
{ |
| 40 |
$this->imagePath = $imagePath; |
| 41 |
|
| 42 |
return $this; |
| 43 |
} |
| 44 |
|
| 45 |
public function setOptions(array $options = []) |
| 46 |
{ |
| 47 |
$this->options = $options; |
| 48 |
|
| 49 |
return $this; |
| 50 |
} |
| 51 |
|
| 52 |
public function getCommand(): string |
| 53 |
{ |
| 54 |
$optionString = implode(' ', $this->options); |
| 55 |
|
| 56 |
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString} ".escapeshellarg($this->imagePath); |
| 57 |
} |
| 58 |
|
| 59 |
public function getTmpPath(): ?string |
| 60 |
{ |
| 61 |
return $this->tmpPath; |
| 62 |
} |
| 63 |
} |
| 64 |
|