CommandUtility
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']
Table of Contents
Properties
- $applications : array<string|int, mixed>
- 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'.
- $initialized : bool
- Tells if object is already initialized
- $paths : array<string|int, mixed>
- Paths where to search for applications
Methods
- addPaths() : mixed
- Extend the preset paths. This way an extension can install an executable and provide the path to \TYPO3\CMS\Core\Utility\CommandUtility
- checkCommand() : bool
- Checks if a command is valid or not, updates global variables
- escapeShellArgument() : string
- Escape a shell argument (for example a filename) to be used on the local system.
- escapeShellArguments() : array<string|int, string>
- Escape shell arguments (for example filenames) to be used on the local system.
- exec() : string
- Wrapper function for php exec function Needs to be central to have better control and possible fix for issues
- getCommand() : mixed
- Returns a command string for exec(), system()
- getPaths() : array<string|int, mixed>
- Returns an array of search paths
- imageMagickCommand() : string
- Compile the command for running ImageMagick/GraphicsMagick.
- fixPath() : string
- Set a path to the right format
- getConfiguredApps() : array<string|int, mixed>
- Processes and returns the paths from $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']
- getPathsInternal() : array<string|int, mixed>
- Sets the search paths from different sources, internal
- init() : bool
- Initializes this class
- initPaths() : mixed
- Initializes and extends the preset paths with own
- unQuoteFilenames() : array<string|int, mixed>
- Explode a string (normally a list of filenames) with whitespaces by considering quotes in that string.
Properties
$applications
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'.
protected
static array<string|int, mixed>
$applications
= []
$initialized
Tells if object is already initialized
protected
static bool
$initialized
= false
$paths
Paths where to search for applications
protected
static array<string|int, mixed>
$paths
Methods
addPaths()
Extend the preset paths. This way an extension can install an executable and provide the path to \TYPO3\CMS\Core\Utility\CommandUtility
public
static addPaths(string $paths) : mixed
Parameters
- $paths : string
-
Comma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with public web path
checkCommand()
Checks if a command is valid or not, updates global variables
public
static checkCommand(string $cmd[, string $handler = '' ]) : bool
Parameters
- $cmd : string
-
The command that should be executed. eg: "convert"
- $handler : string = ''
-
Executer for the command. eg: "perl"
Return values
bool —FALSE if cmd is not found, or -1 if the handler is not found
escapeShellArgument()
Escape a shell argument (for example a filename) to be used on the local system.
public
static escapeShellArgument(string $input) : string
The setting UTF8filesystem will be taken into account.
Parameters
- $input : string
-
Input-argument to be escaped
Return values
string —Escaped shell argument
escapeShellArguments()
Escape shell arguments (for example filenames) to be used on the local system.
public
static escapeShellArguments(array<string|int, string> $input) : array<string|int, string>
The setting UTF8filesystem will be taken into account.
Parameters
- $input : array<string|int, string>
-
Input arguments to be escaped
Return values
array<string|int, string> —Escaped shell arguments
exec()
Wrapper function for php exec function Needs to be central to have better control and possible fix for issues
public
static exec(string $command[, array<string|int, mixed>|null &$output = null ][, int &$returnValue = 0 ]) : string
Parameters
- $command : string
- $output : array<string|int, mixed>|null = null
- $returnValue : int = 0
Return values
stringgetCommand()
Returns a command string for exec(), system()
public
static getCommand(string $cmd[, string $handler = '' ][, string $handlerOpt = '' ]) : mixed
Parameters
- $cmd : string
-
The command that should be executed. eg: "convert"
- $handler : string = ''
-
Handler (executor) for the command. eg: "perl"
- $handlerOpt : string = ''
-
Options for the handler, like '-w' for "perl"
Return values
mixed —Returns command string, or FALSE if cmd is not found, or -1 if the handler is not found
getPaths()
Returns an array of search paths
public
static getPaths([bool $addInvalid = false ]) : array<string|int, mixed>
Parameters
- $addInvalid : bool = false
-
If set the array contains invalid path too. Then the key is the path and the value is empty
Return values
array<string|int, mixed> —Array of search paths (empty if exec is disabled)
imageMagickCommand()
Compile the command for running ImageMagick/GraphicsMagick.
public
static imageMagickCommand(string $command, string $parameters[, string $path = '' ]) : string
Parameters
- $command : string
-
Command to be run: identify, convert or combine/composite
- $parameters : string
-
The parameters string
- $path : string = ''
-
Override the default path (e.g. used by the install tool)
Return values
string —Compiled command that deals with ImageMagick & GraphicsMagick
fixPath()
Set a path to the right format
protected
static fixPath(string $path) : string
Parameters
- $path : string
-
Input path
Return values
string —Output path
getConfiguredApps()
Processes and returns the paths from $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']
protected
static getConfiguredApps() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of commands and path
getPathsInternal()
Sets the search paths from different sources, internal
protected
static getPathsInternal() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of absolute paths (keys and values are equal)
init()
Initializes this class
protected
static init() : bool
Return values
boolinitPaths()
Initializes and extends the preset paths with own
protected
static initPaths([string $paths = '' ]) : mixed
Parameters
- $paths : string = ''
-
Comma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with public web path
unQuoteFilenames()
Explode a string (normally a list of filenames) with whitespaces by considering quotes in that string.
protected
static unQuoteFilenames(string $parameters) : array<string|int, mixed>
Parameters
- $parameters : string
-
The whole parameters string
Return values
array<string|int, mixed> —Exploded parameters