MediaWiki  1.30.0
MediaWiki\Shell\Command Class Reference

Class used for executing shell commands. More...

Collaboration diagram for MediaWiki\Shell\Command:

Public Member Functions

 __construct ()
 Constructor. More...
 
 __destruct ()
 Destructor. More...
 
 cgroup ( $cgroup)
 Sets cgroup for this command. More...
 
 environment (array $env)
 Sets environment variables which should be added to the executed command environment. More...
 
 execute ()
 Executes command. More...
 
 includeStderr ( $yesno=true)
 Controls whether stderr should be included in stdout, including errors from limit.sh. More...
 
 limits (array $limits)
 Sets execution limits. More...
 
 params ()
 Adds parameters to the command. More...
 
 profileMethod ( $method)
 Sets calling function for profiler. More...
 
 unsafeParams ()
 Adds unsafe parameters to the command. More...
 

Private Attributes

string false $cgroup = false
 
string $command = ''
 
string[] $env = []
 
bool $everExecuted = false
 
array $limits
 
string $method
 
bool $useStderr = false
 

Detailed Description

Class used for executing shell commands.

Since
1.30

Definition at line 35 of file Command.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Shell\Command::__construct ( )

Constructor.

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

Exceptions
ShellDisabledError

Definition at line 73 of file Command.php.

References MediaWiki\Shell\Shell\isDisabled().

◆ __destruct()

MediaWiki\Shell\Command::__destruct ( )

Destructor.

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

Definition at line 84 of file Command.php.

References MediaWiki\Shell\Command\$command, MediaWiki\$context, and MediaWiki\Shell\Command\$method.

Member Function Documentation

◆ cgroup()

MediaWiki\Shell\Command::cgroup (   $cgroup)

Sets cgroup for this command.

Parameters
string | false$cgroupAbsolute file path to the cgroup, or false to not use a cgroup
Returns
$this

Definition at line 201 of file Command.php.

References MediaWiki\Shell\Command\$cgroup.

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

◆ environment()

MediaWiki\Shell\Command::environment ( array  $env)

Sets environment variables which should be added to the executed command environment.

Parameters
string[]$envarray of variable name => value
Returns
$this

Definition at line 164 of file Command.php.

References MediaWiki\Shell\Command\$env.

◆ execute()

MediaWiki\Shell\Command::execute ( )

Executes command.

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

Returns
Result
Exceptions
Exception
ProcOpenError
ShellDisabledError

Definition at line 216 of file Command.php.

References $line, $lines, $retval, $time, as, MediaWiki\Shell\Command\cgroup(), Profiler\instance(), MediaWiki\Shell\Command\limits(), SHELL_MAX_ARG_STRLEN, wfDebug(), wfGetCaller(), and wfIsWindows().

◆ includeStderr()

MediaWiki\Shell\Command::includeStderr (   $yesno = true)

Controls whether stderr should be included in stdout, including errors from limit.sh.

Default: don't include.

Parameters
bool$yesno
Returns
$this

Definition at line 189 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 147 of file Command.php.

References MediaWiki\Shell\Command\$limits.

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

◆ params()

MediaWiki\Shell\Command::params ( )

Adds parameters to the command.

All parameters are sanitized via Shell::escape(). Null values are ignored.

Parameters
string | string[]$args,...
Returns
$this

Definition at line 104 of file Command.php.

References $args, captcha-old\count, and MediaWiki\Shell\Shell\escape().

◆ profileMethod()

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

Sets calling function for profiler.

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

Parameters
string$method
Returns
$this

Definition at line 176 of file Command.php.

References MediaWiki\Shell\Command\$method.

◆ unsafeParams()

MediaWiki\Shell\Command::unsafeParams ( )

Adds unsafe parameters to the command.

These parameters are NOT sanitized in any way. Null values are ignored.

Parameters
string | string[]$args,...
Returns
$this

Definition at line 123 of file Command.php.

References $args, $value, and captcha-old\count.

Member Data Documentation

◆ $cgroup

string false MediaWiki\Shell\Command::$cgroup = false
private

Definition at line 66 of file Command.php.

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

◆ $command

string MediaWiki\Shell\Command::$command = ''
private

Definition at line 39 of file Command.php.

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

◆ $env

string [] MediaWiki\Shell\Command::$env = []
private

Definition at line 54 of file Command.php.

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

◆ $everExecuted

bool MediaWiki\Shell\Command::$everExecuted = false
private

Definition at line 63 of file Command.php.

◆ $limits

array MediaWiki\Shell\Command::$limits
private
Initial value:
= [
'time' => 180,
'walltime' => 180,
'memory' => 307200,
'filesize' => 102400,
]

Definition at line 42 of file Command.php.

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

◆ $method

string MediaWiki\Shell\Command::$method
private

◆ $useStderr

bool MediaWiki\Shell\Command::$useStderr = false
private

Definition at line 60 of file Command.php.


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