ShellManager.php in FillPDF 5.0.x
File
src/ShellManager.php
View source
<?php
namespace Drupal\fillpdf;
use Drupal\Core\Config\ConfigFactoryInterface;
class ShellManager implements ShellManagerInterface {
protected $configFactory;
protected $isWindows;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
$this->isWindows = substr(PHP_OS, 0, 3) === 'WIN';
}
public function isWindows() {
return $this->isWindows;
}
public function getInstalledLocales() {
if ($this
->isWindows()) {
return [];
}
$output = [];
$status = NULL;
exec("locale -a", $output, $status);
return array_combine($output, $output);
}
public function escapeShellArg($arg) {
static $config_locale;
if (!isset($config_locale)) {
$config_locale = $this->configFactory
->get('fillpdf.settings')
->get('shell_locale');
}
$current_locale = setlocale(LC_CTYPE, 0);
if ($this
->isWindows()) {
$arg = str_replace('%', static::PERCENTAGE_REPLACE, $arg);
}
if ($current_locale !== $config_locale) {
setlocale(LC_CTYPE, [
$config_locale,
'C.UTF-8',
$current_locale,
]);
}
$arg_escaped = escapeshellarg($arg);
if ($current_locale !== $config_locale) {
setlocale(LC_CTYPE, $current_locale);
}
if ($this
->isWindows()) {
$arg_escaped = str_replace(static::PERCENTAGE_REPLACE, '%', $arg_escaped);
}
return $arg_escaped;
}
}