MediaWiki master
MediaWiki\Shell\Command Class Reference

Class used for executing shell commands. More...

Inherits UnboxedCommand.

Collaboration diagram for MediaWiki\Shell\Command:

Public Member Functions

 __construct (UnboxedExecutor $executor)
 Don't call directly, instead use Shell::command()
 
 __destruct ()
 Makes sure the programmer didn't forget to execute the command after all.
 
 __toString ()
 Returns the final command line before environment/limiting, etc are applied.
 
 execute ()
 Executes command.
 
 input (string $inputString)
 Sends the provided input to the command.
 
 limits (array $limits)
 Sets execution limits.
 
 profileMethod (string $method)
 Sets calling function for profiler.
 
 restrict (int $restrictions)
 Set restrictions for this request, overwriting any previously set restrictions.
 
 setLogger (LoggerInterface $logger)
 
 whitelistPaths (array $paths)
 If called, only the files/directories that are whitelisted will be available to the shell command.
 

Protected Attributes

LoggerInterface $logger
 

Detailed Description

Class used for executing shell commands.

Since
1.30

Definition at line 38 of file Command.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Shell\Command::__construct ( UnboxedExecutor $executor)

Don't call directly, instead use Shell::command()

Parameters
UnboxedExecutor$executor
Exceptions
ShellDisabledError

Definition at line 52 of file Command.php.

References MediaWiki\Shell\Shell\isDisabled(), and MediaWiki\Shell\Command\setLogger().

◆ __destruct()

MediaWiki\Shell\Command::__destruct ( )

Makes sure the programmer didn't forget to execute the command after all.

Definition at line 63 of file Command.php.

Member Function Documentation

◆ __toString()

MediaWiki\Shell\Command::__toString ( )

Returns the final command line before environment/limiting, etc are applied.

Use string conversion only for debugging, don't try to pass this to some other execution medium.

Returns
string

Definition at line 226 of file Command.php.

◆ execute()

MediaWiki\Shell\Command::execute ( )

Executes command.

Afterwards, getExitCode() and getOutput() can be used to access execution results.

Returns
UnboxedResult
Exceptions
Exception

Definition at line 210 of file Command.php.

◆ input()

MediaWiki\Shell\Command::input ( string $inputString)

Sends the provided input to the command.

Defaults to an empty string. If you want to pass stdin through to the command instead, use passStdin().

Parameters
string$inputString
Returns
$this

Definition at line 135 of file Command.php.

◆ limits()

MediaWiki\Shell\Command::limits ( array $limits)

Sets execution limits.

Parameters
array$limitsAssociative array of limits. Keys (all optional): filesize (for ulimit -f), memory, time, walltime.
Returns
$this

Definition at line 93 of file Command.php.

◆ profileMethod()

MediaWiki\Shell\Command::profileMethod ( string $method)

Sets calling function for profiler.

By default, the caller for execute() will be used.

Parameters
string$method
Returns
$this

Definition at line 121 of file Command.php.

◆ restrict()

MediaWiki\Shell\Command::restrict ( int $restrictions)

Set restrictions for this request, overwriting any previously set restrictions.

Add the "no network" restriction:

$command->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK );

Allow LocalSettings.php access:

$command->restrict( Shell::RESTRICT_DEFAULT & ~Shell::NO_LOCALSETTINGS );

Disable all restrictions:

$command->restrict( Shell::RESTRICT_NONE );
Deprecated
since 1.36 Set the options using their separate accessors
Since
1.31
Parameters
int$restrictions
Returns
$this

Definition at line 163 of file Command.php.

◆ setLogger()

MediaWiki\Shell\Command::setLogger ( LoggerInterface $logger)
Parameters
LoggerInterface$logger

Definition at line 79 of file Command.php.

References MediaWiki\Shell\Command\$logger.

Referenced by MediaWiki\Shell\Command\__construct().

◆ whitelistPaths()

MediaWiki\Shell\Command::whitelistPaths ( array $paths)

If called, only the files/directories that are whitelisted will be available to the shell command.

limit.sh will always be whitelisted

Deprecated
since 1.36 Use allowPath/disallowPath. Hard deprecated in 1.40 and to be removed in 1.41
Parameters
string[]$paths
Returns
$this

Definition at line 197 of file Command.php.

Member Data Documentation

◆ $logger

LoggerInterface MediaWiki\Shell\Command::$logger
protected

Definition at line 44 of file Command.php.

Referenced by MediaWiki\Shell\Command\setLogger().


The documentation for this class was generated from the following file: