class ShellManager in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x src/ShellManager.php \Drupal\fillpdf\ShellManager
Manage execution of shell commands.
@internal
Hierarchy
- class \Drupal\fillpdf\ShellManager implements ShellManagerInterface
Expanded class hierarchy of ShellManager
2 files declare their use of ShellManager
- FillPdfSettingsForm.php in src/
Form/ FillPdfSettingsForm.php - PdftkPdfBackend.php in src/
Plugin/ PdfBackend/ PdftkPdfBackend.php
1 string reference to 'ShellManager'
1 service uses ShellManager
File
- src/
ShellManager.php, line 12
Namespace
Drupal\fillpdfView source
class ShellManager implements ShellManagerInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Whether we are running on Windows OS.
*
* @var bool
*/
protected $isWindows;
/**
* Constructs a ShellManager object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
$this->isWindows = substr(PHP_OS, 0, 3) === 'WIN';
}
/**
* {@inheritdoc}
*/
public function isWindows() {
return $this->isWindows;
}
/**
* {@inheritdoc}
*/
public function getInstalledLocales() {
if ($this
->isWindows()) {
return [];
}
$output = [];
$status = NULL;
exec("locale -a", $output, $status);
return array_combine($output, $output);
}
/**
* {@inheritdoc}
*/
public function escapeShellArg($arg) {
// Put the configured locale in a static to avoid multiple config get calls
// in the same request.
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()) {
// Temporarily replace % characters.
$arg = str_replace('%', static::PERCENTAGE_REPLACE, $arg);
}
if ($current_locale !== $config_locale) {
// Temporarily swap the current locale with the configured one, if
// available. Otherwise fall back.
setlocale(LC_CTYPE, [
$config_locale,
'C.UTF-8',
$current_locale,
]);
}
$arg_escaped = escapeshellarg($arg);
if ($current_locale !== $config_locale) {
// Restore the current locale.
setlocale(LC_CTYPE, $current_locale);
}
// Get our % characters back.
if ($this
->isWindows()) {
$arg_escaped = str_replace(static::PERCENTAGE_REPLACE, '%', $arg_escaped);
}
return $arg_escaped;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ShellManager:: |
protected | property | The configuration factory. | |
ShellManager:: |
protected | property | Whether we are running on Windows OS. | |
ShellManager:: |
public | function |
Escapes a string. Overrides ShellManagerInterface:: |
|
ShellManager:: |
public | function |
Gets the list of locales installed on the server. Overrides ShellManagerInterface:: |
|
ShellManager:: |
public | function |
Whether we are running on Windows OS. Overrides ShellManagerInterface:: |
|
ShellManager:: |
public | function | Constructs a ShellManager object. | |
ShellManagerInterface:: |
constant | Replacement for percentage while escaping. |