TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Utility\CommandUtility Class Reference

Static Public Member Functions

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

Static Protected Member Functions

static init ()
 
static initPaths ($paths='')
 
static getConfiguredApps ()
 
static getPathsInternal ()
 
static fixPath ($path)
 

Static Protected Attributes

static $initialized = false
 
static $applications = []
 
static $paths = null
 

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']['im_path_lzw'] or $TYPO3_CONF_VARS['GFX']['im_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 45 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

Parameters
string$pathsComma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with site root path (PATH_site).
Returns
void

Definition at line 258 of file CommandUtility.php.

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

◆ checkCommand()

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

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

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

Definition at line 155 of file CommandUtility.php.

Referenced by TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isServiceAvailable().

◆ escapeShellArgument()

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

Escape a shell argument (for example a filename) to be used on the local system.

The setting UTF8filesystem will be taken into account.

Parameters
string$inputInput-argument to be escaped
Returns
string Escaped shell argument

Definition at line 470 of file CommandUtility.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\combineExec(), TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper\getTemporaryFilePath(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickExec(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickIdentify(), and TYPO3\CMS\Backend\View\ThumbnailView\main().

◆ escapeShellArguments()

static 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 445 of file CommandUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Scheduler\Scheduler\log(), and TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing\resizeImage().

◆ exec()

static TYPO3\CMS\Core\Utility\CommandUtility::exec (   $command,
$output = null,
$returnValue = 0 
)
static

◆ fixPath()

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

Set a path to the right format

Parameters
string$pathInput path
Returns
string Output path

Definition at line 432 of file CommandUtility.php.

◆ getCommand()

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

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

Parameters
string$cmdThe command that should be executed. eg: "convert"
string$handlerHandler (executor) for the command. eg: "perl"
string$handlerOptOptions 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 227 of file CommandUtility.php.

Referenced by TYPO3\CMS\Rsaauth\Backend\CommandLineBackend\__construct().

◆ getConfiguredApps()

static 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 355 of file CommandUtility.php.

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

◆ getPaths()

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

Returns an array of search paths

Parameters
bool$addInvalidIf 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 269 of file CommandUtility.php.

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

Referenced by TYPO3\CMS\Sv\Report\ServicesListReport\renderExecutablesSearchPathList().

◆ getPathsInternal()

static 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 381 of file CommandUtility.php.

References $GLOBALS, $sep, and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ imageMagickCommand()

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

Compile the command for running ImageMagick/GraphicsMagick.

Parameters
string$commandCommand to be run: identify, convert or combine/composite
string$parametersThe parameters string
string$pathOverride the default path (e.g. used by the install tool)
Returns
string Compiled command that deals with IM6 & GraphicsMagick

Definition at line 96 of file CommandUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\GeneralUtility\fixWindowsFilePath(), and TYPO3\CMS\Core\Utility\GeneralUtility\unQuoteFilenames().

Referenced by TYPO3\CMS\Install\Controller\Action\Tool\TestSetup\determineImageMagickVersion(), and TYPO3\CMS\Core\Utility\GeneralUtility\imageMagickCommand().

◆ init()

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

Initializes this class

Returns
bool

Definition at line 292 of file CommandUtility.php.

References $GLOBALS.

◆ initPaths()

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

Initializes and extends the preset paths with own

Parameters
string$pathsComma separated list of extra paths where a command should be searched. Relative paths (without leading "/") are prepend with site root path (PATH_site).
Returns
void

Definition at line 311 of file CommandUtility.php.

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

Member Data Documentation

◆ $applications

TYPO3\CMS\Core\Utility\CommandUtility::$applications = []
staticprotected

Definition at line 63 of file CommandUtility.php.

◆ $initialized

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

Definition at line 52 of file CommandUtility.php.

◆ $paths

TYPO3\CMS\Core\Utility\CommandUtility::$paths = null
staticprotected