ShellOperations.php in Image Optimize Binaries 8
File
src/ShellOperations.php
View source
<?php
namespace Drupal\imageapi_optimize_binaries;
use Drupal\Core\File\FileSystemInterface;
class ShellOperations implements ImageAPIOptimizeShellOperationsInterface {
public function findExecutablePath($executable = NULL) {
$output = array();
$return_var = 0;
$path = exec('which ' . escapeshellarg($executable), $output, $return_var);
if ($return_var == 0) {
return $path;
}
return FALSE;
}
public function execShellCommand($command, $options, $arguments) {
$output = array();
$return_val = 0;
$option_string = implode(' ', $options);
$argument_string = implode(' ', array_map('escapeshellarg', $arguments));
exec(escapeshellcmd($command) . ' ' . $option_string . ' ' . $argument_string, $output, $return_val);
if ($return_val == 0) {
return TRUE;
}
else {
return FALSE;
}
}
public function saveCommandStdoutToFile($cmd, $dst) {
$return_val = 0;
ob_start();
passthru($cmd);
$output = ob_get_contents();
ob_end_clean();
\Drupal::service('file_system')
->saveData($output, $dst, FileSystemInterface::EXISTS_REPLACE);
if ($return_val == 0) {
return TRUE;
}
else {
return FALSE;
}
}
}
Classes
Name |
Description |
ShellOperations |
Storage controller class for "image optimize pipeline" configuration entities. |