‪TYPO3CMS  10.4
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)
static

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

Parameters
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 262 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 = '' 
)
static

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

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

Definition at line 160 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)
static

◆ escapeShellArguments()

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

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

The setting UTF8filesystem will be taken into account.

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

Definition at line 448 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)
staticprotected

Set a path to the right format

Parameters
string$path‪Input path
Returns
‪string Output path

Definition at line 435 of file CommandUtility.php.

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

◆ getCommand()

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

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

Parameters
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"
Returns
‪mixed Returns command string, or FALSE if cmd is not found, or -1 if the handler is not found

Definition at line 232 of file CommandUtility.php.

◆ getConfiguredApps()

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

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

Returns
‪array Array of commands and path

Definition at line 358 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)
static

Returns an array of search paths

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

Definition at line 273 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 ( )
staticprotected

Sets the search paths from different sources, internal

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

Definition at line 384 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,
  $parameters,
  $path = '' 
)
static

◆ init()

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

Initializes this class

Returns
‪bool

Definition at line 296 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 = '')
staticprotected

Initializes and extends the preset paths with own

Parameters
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 314 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)
staticprotected

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

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

Definition at line 472 of file CommandUtility.php.

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

Member Data Documentation

◆ $applications

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

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
staticprotected

Tells if object is already initialized

Definition at line 54 of file CommandUtility.php.

◆ $paths

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