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'] $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, array{app: string, path: string, valid: bool}>
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, string|false>|null
Paths where to search for applications

Methods

addPaths()  : void
Extend the preset paths. This way an extension can install an executable and provide the path to \TYPO3\CMS\Core\Utility\CommandUtility
checkCommand()  : bool|int
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|false
Execute a shell command.
getCommand()  : string|bool|int
Returns a command string for exec(), system()
getPaths()  : array<string, string|false>
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, array{app: string, path: string, valid: bool}>
Processes and returns the paths from $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']
getLogger()  : LoggerInterface
getPathsInternal()  : array<string, string>
Sets the search paths from different sources, internal
init()  : bool
Initializes this class
initPaths()  : void
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, array{app: string, path: string, valid: bool}> $applications = []

$initialized

Tells if object is already initialized

protected static bool $initialized = false

$paths

Paths where to search for applications

protected static array<string, string|false>|null $paths = null

The key is a path. The value is either the same path, or false if the path is not valid.

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) : void
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|int
Parameters
$cmd : string

The command that should be executed. eg: "convert"

$handler : string = ''

Executor for the command. eg: "perl"

Return values
bool|int

True if the command is valid; False if cmd is not found; -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()

Execute a shell command.

public static exec(string|array<string|int, mixed> $command[, array<string|int, mixed>|null &$output = null ][, int &$returnValue = 0 ]) : string|false

Needs to be central to have better control and possible fix for issues. Is a wrapper for Symfony's Process component.

Parameters
$command : string|array<string|int, mixed>
$output : array<string|int, mixed>|null = null
$returnValue : int = 0
Tags
see
Process
Return values
string|false

getCommand()

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

public static getCommand(string $cmd[, string $handler = '' ][, string $handlerOpt = '' ]) : string|bool|int
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
string|bool|int

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, string|false>
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, string|false>

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, array{app: string, path: string, valid: bool}>
Return values
array<string, array{app: string, path: string, valid: bool}>

Array of commands and path

getLogger()

protected static getLogger() : LoggerInterface
Return values
LoggerInterface

getPathsInternal()

Sets the search paths from different sources, internal

protected static getPathsInternal() : array<string, string>
Return values
array<string, string>

Array of absolute paths (keys and values are equal)

init()

Initializes this class

protected static init() : bool
Return values
bool

initPaths()

Initializes and extends the preset paths with own

protected static initPaths([string $paths = '' ]) : void
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


        
On this page

Search results