TYPO3  7.6
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
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 = array()
 
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

static 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 CommandUtility\$paths.

static 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 ExtensionManagementUtility\isServiceAvailable().

static 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 GraphicalFunctions\combineExec(), GraphicalFunctions\imageMagickExec(), GraphicalFunctions\imageMagickIdentify(), and ThumbnailView\main().

static 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 PreviewProcessing\resizeImage().

static exec (   $command,
$output = null,
$returnValue = 0 
)
static

Wrapper function for php exec function Needs to be central to have better control and possible fix for issues

Parameters
string$command
NULL | array$output
int$returnValue
Returns
NULL|array

Definition at line 82 of file CommandUtility.php.

Referenced by CommandLineBackend\decrypt(), FileContentParser\fileContentParts(), ExtendedFileUtility\func_unzip(), SystemInformationToolbarItem\getGitRevision(), GraphicalFunctions\gifCompress(), CommandLineBackend\isAvailable(), FileContentParser\readFileContent(), GraphicalFunctions\readPngGif(), and PreviewProcessing\resizeImage().

static 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.

static 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 CommandLineBackend\__construct().

static 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 GeneralUtility\trimExplode().

static 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 CommandUtility\$paths.

Referenced by ServicesListReport\renderExecutablesSearchPathList().

static 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, and GeneralUtility\trimExplode().

static 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, GeneralUtility\fixWindowsFilePath(), and GeneralUtility\unQuoteFilenames().

Referenced by GeneralUtility\imageMagickCommand().

static init ( )
staticprotected

Initializes this class

Returns
bool

Definition at line 292 of file CommandUtility.php.

References $GLOBALS.

static 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 CommandUtility\$paths, and GeneralUtility\trimExplode().

Member Data Documentation

$applications = array()
staticprotected

Definition at line 63 of file CommandUtility.php.

$initialized = false
staticprotected

Definition at line 52 of file CommandUtility.php.

$paths = null
staticprotected