‪TYPO3CMS  11.5
TYPO3\CMS\Core\Utility\CommandUtility Class Reference

Static Public Member Functions

static string exec ($command, &$output=null, &$returnValue=0)
static string imageMagickCommand ($command, $parameters, $path='')
static bool checkCommand ($cmd, $handler='')
static mixed getCommand ($cmd, $handler='', $handlerOpt='')
static addPaths ($paths)
static array getPaths ($addInvalid=false)
static string[] escapeShellArguments (array $input)
static string escapeShellArgument ($input)

Static Protected Member Functions

static bool init ()
static initPaths ($paths='')
static array getConfiguredApps ()
static array getPathsInternal ()
static string fixPath ($path)
static array unQuoteFilenames (string $parameters)

Static Protected Attributes

static bool $initialized = false
static array $applications = array( )
static array $paths

Detailed Description

Class to handle system commands. finds executables (programs) on Unix and Windows without knowing where they are

returns exec command for a program or FALSE

This class is meant to be used without instance: $cmd = CommandUtility::getCommand ('awstats','perl');

The data of this class is cached. That means if a program is found once it don't have to be searched again.

user functions:

addPaths() could be used to extend the search paths getCommand() get a command string checkCommand() returns TRUE if a command is available

Search paths that are included: $TYPO3_CONF_VARS['GFX']['processor_path_lzw'] or $TYPO3_CONF_VARS['GFX']['processor_path'] $TYPO3_CONF_VARS['SYS']['binPath'] $GLOBALS['_SERVER']['PATH'] '/usr/bin/,/usr/local/bin/' on Unix

binaries can be preconfigured with $TYPO3_CONF_VARS['SYS']['binSetup']

Definition at line 48 of file CommandUtility.php.

Member Function Documentation

◆ addPaths()

static TYPO3\CMS\Core\Utility\CommandUtility::addPaths (   $paths)

Extend the preset paths. This way an extension can install an executable and provide the path to \TYPO3\CMS\Core\Utility\CommandUtility

string$paths‪Comma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with public web path

Definition at line 266 of file CommandUtility.php.

References TYPO3\CMS\Core\Utility\CommandUtility\$paths, and TYPO3\CMS\Core\Utility\CommandUtility\initPaths().

◆ checkCommand()

static bool TYPO3\CMS\Core\Utility\CommandUtility::checkCommand (   $cmd,
  $handler = '' 

Checks if a command is valid or not, updates global variables

string$cmd‪The command that should be executed. eg: "convert"
string$handler‪Executer for the command. eg: "perl"
‪bool FALSE if cmd is not found, or -1 if the handler is not found

Definition at line 164 of file CommandUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\dirname(), TYPO3\CMS\Core\Utility\CommandUtility\exec(), and TYPO3\CMS\Core\Core\Environment\isWindows().

Referenced by TYPO3\CMS\Core\Service\AbstractService\checkExec(), and TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isServiceAvailable().

◆ escapeShellArgument()

static string TYPO3\CMS\Core\Utility\CommandUtility::escapeShellArgument (   $input)

◆ escapeShellArguments()

static string [] TYPO3\CMS\Core\Utility\CommandUtility::escapeShellArguments ( array  $input)

Escape shell arguments (for example filenames) to be used on the local system.

The setting UTF8filesystem will be taken into account.

string[]$input‪Input arguments to be escaped
‪string[] Escaped shell arguments

Definition at line 452 of file CommandUtility.php.

References $GLOBALS, and $output.

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\escapeShellArgument(), and TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper\generatePreviewFromLocalFile().

◆ exec()

◆ fixPath()

static string TYPO3\CMS\Core\Utility\CommandUtility::fixPath (   $path)

Set a path to the right format

string$path‪Input path
‪string Output path

Definition at line 439 of file CommandUtility.php.

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\getPathsInternal().

◆ getCommand()

static mixed TYPO3\CMS\Core\Utility\CommandUtility::getCommand (   $cmd,
  $handler = '',
  $handlerOpt = '' 

Returns a command string for exec(), system()

string$cmd‪The command that should be executed. eg: "convert"
string$handler‪Handler (executor) for the command. eg: "perl"
string$handlerOpt‪Options for the handler, like '-w' for "perl"
‪mixed Returns command string, or FALSE if cmd is not found, or -1 if the handler is not found

Definition at line 236 of file CommandUtility.php.

◆ getConfiguredApps()

static array TYPO3\CMS\Core\Utility\CommandUtility::getConfiguredApps ( )

Processes and returns the paths from $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']

‪array Array of commands and path

Definition at line 362 of file CommandUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\PathUtility\basename(), TYPO3\CMS\Core\Utility\PathUtility\dirname(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\init().

◆ getPaths()

static array TYPO3\CMS\Core\Utility\CommandUtility::getPaths (   $addInvalid = false)

Returns an array of search paths

bool$addInvalid‪If set the array contains invalid path too. Then the key is the path and the value is empty
‪array Array of search paths (empty if exec is disabled)

Definition at line 277 of file CommandUtility.php.

References TYPO3\CMS\Core\Utility\CommandUtility\$paths.

Referenced by TYPO3\CMS\Reports\Report\ServicesListReport\getExecutablesSearchPathList().

◆ getPathsInternal()

static array TYPO3\CMS\Core\Utility\CommandUtility::getPathsInternal ( )

Sets the search paths from different sources, internal

‪array Array of absolute paths (keys and values are equal)

Definition at line 388 of file CommandUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\CommandUtility\fixPath(), TYPO3\CMS\Core\Core\Environment\isWindows(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\initPaths().

◆ imageMagickCommand()

static string TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand (   $command,
  $path = '' 

◆ init()

static bool TYPO3\CMS\Core\Utility\CommandUtility::init ( )

Initializes this class


Definition at line 300 of file CommandUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\CommandUtility\getConfiguredApps(), and TYPO3\CMS\Core\Utility\CommandUtility\initPaths().

◆ initPaths()

static TYPO3\CMS\Core\Utility\CommandUtility::initPaths (   $paths = '')

Initializes and extends the preset paths with own

string$paths‪Comma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with public web path

Definition at line 318 of file CommandUtility.php.

References TYPO3\CMS\Core\Utility\CommandUtility\$paths, TYPO3\CMS\Core\Utility\CommandUtility\getPathsInternal(), TYPO3\CMS\Core\Core\Environment\getPublicPath(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\addPaths(), and TYPO3\CMS\Core\Utility\CommandUtility\init().

◆ unQuoteFilenames()

static array TYPO3\CMS\Core\Utility\CommandUtility::unQuoteFilenames ( string  $parameters)

Explode a string (normally a list of filenames) with whitespaces by considering quotes in that string.

string$parameters‪The whole parameters string
‪array Exploded parameters

Definition at line 476 of file CommandUtility.php.

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\imageMagickCommand().

Member Data Documentation

◆ $applications

array TYPO3\CMS\Core\Utility\CommandUtility::$applications = array( )

Contains application list. This is an array with the following structure:

  • ‪app => file name to the application (like 'tar' or 'bzip2')
  • ‪path => full path to the application without application name (like '/usr/bin/' for '/usr/bin/tar')
  • ‪valid => TRUE or FALSE Array key is identical to 'app'.

Definition at line 64 of file CommandUtility.php.

◆ $initialized

bool TYPO3\CMS\Core\Utility\CommandUtility::$initialized = false

Tells if object is already initialized

Definition at line 54 of file CommandUtility.php.

◆ $paths

array TYPO3\CMS\Core\Utility\CommandUtility::$paths