Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ImageOptimizer/ChainOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class ChainOptimizer implements Optimizer
/**
* @var Optimizer[]
*/
private $optimizers;
private $executeFirst;
private $logger;
public $optimizers;
public $executeFirst;
public $logger;

public function __construct(array $optimizers, bool $executeFirst, LoggerInterface $logger)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ImageOptimizer/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

final class Command
{
private $cmd;
private $args;
private $timeout;
public $cmd;
public $args;
public $timeout;

public function __construct(string $bin, array $args = [], ?float $timeout = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ImageOptimizer/CommandOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class CommandOptimizer implements Optimizer
{
private $command;
private $extraArgs;
public $command;
public $extraArgs;

public function __construct(Command $command, $extraArgs = null)
{
Expand Down
28 changes: 28 additions & 0 deletions src/ImageOptimizer/OptimizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ function ($filepath) {
]));
}

public function checkOptimizers()
{
$apps = [];

// Get a complete list of apps we currently support
foreach ($this->optimizers as $optimizer) {
$unwrapped = $optimizer->unwrap();

if ($unwrapped instanceof ChainOptimizer) {
foreach ($unwrapped->optimizers as $commandOptimizer) {
$apps[$commandOptimizer->command->cmd] = false;
}
} elseif ($unwrapped instanceof CommandOptimizer) {
$apps[$unwrapped->command->cmd] = false;
}
}

// Loop through our apps calling 'which' on them to see if they're installed
foreach (array_keys($apps) as $app) {
$process = new \Symfony\Component\Process\Process(['which', $app]);
$process->run();

$apps[$app] = $process->isSuccessful();
}

return $apps;
}

private function commandOptimizer(string $command, array $args, $extraArgs = null): CommandOptimizer
{
return new CommandOptimizer(
Expand Down