MediaWiki  REL1_31
CommandFactory.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Shell;
22 
24 use Psr\Log\LoggerAwareTrait;
25 use Psr\Log\NullLogger;
26 
33  use LoggerAwareTrait;
34 
36  private $limits;
37 
39  private $cgroup;
40 
42  private $doLogStderr = false;
43 
48 
52  private $firejail;
53 
62  $this->limits = $limits;
63  $this->cgroup = $cgroup;
64  if ( $restrictionMethod === 'autodetect' ) {
65  // On Linux systems check for firejail
66  if ( PHP_OS === 'Linux' && $this->findFirejail() !== false ) {
67  $this->restrictionMethod = 'firejail';
68  } else {
69  $this->restrictionMethod = false;
70  }
71  } else {
72  $this->restrictionMethod = $restrictionMethod;
73  }
74  $this->setLogger( new NullLogger() );
75  }
76 
77  private function findFirejail() {
78  if ( $this->firejail === null ) {
79  $this->firejail = ExecutableFinder::findInDefaultPaths( 'firejail' );
80  }
81 
82  return $this->firejail;
83  }
84 
91  public function logStderr( $yesno = true ) {
92  $this->doLogStderr = $yesno;
93  }
94 
100  public function create() {
101  if ( $this->restrictionMethod === 'firejail' ) {
102  $command = new FirejailCommand( $this->findFirejail() );
103  $command->restrict( Shell::RESTRICT_DEFAULT );
104  } else {
105  $command = new Command();
106  }
107  $command->setLogger( $this->logger );
108 
109  return $command
110  ->limits( $this->limits )
111  ->cgroup( $this->cgroup )
112  ->logStderr( $this->doLogStderr );
113  }
114 }
MediaWiki\Shell\CommandFactory\$limits
array $limits
Definition: CommandFactory.php:36
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\Shell\CommandFactory\logStderr
logStderr( $yesno=true)
When enabled, text sent to stderr will be logged with a level of 'error'.
Definition: CommandFactory.php:91
MediaWiki\Shell\Command
Class used for executing shell commands.
Definition: Command.php:35
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWiki\Shell\CommandFactory\$doLogStderr
bool $doLogStderr
Definition: CommandFactory.php:42
MediaWiki\Shell\CommandFactory\__construct
__construct(array $limits, $cgroup, $restrictionMethod)
Constructor.
Definition: CommandFactory.php:61
MediaWiki\Shell\CommandFactory\$firejail
string bool $firejail
Definition: CommandFactory.php:52
ExecutableFinder
Utility class to find executables in likely places.
Definition: ExecutableFinder.php:28
MediaWiki\Shell\CommandFactory\$restrictionMethod
string bool $restrictionMethod
Definition: CommandFactory.php:47
MediaWiki\Shell\FirejailCommand
Restricts execution of shell commands using firejail.
Definition: FirejailCommand.php:31
$command
$command
Definition: cdb.php:65
MediaWiki\Shell\Shell\RESTRICT_DEFAULT
const RESTRICT_DEFAULT
Apply a default set of restrictions for improved security out of the box.
Definition: Shell.php:56
MediaWiki\Shell\CommandFactory
Factory facilitating dependency injection for Command.
Definition: CommandFactory.php:32
MediaWiki\Shell\CommandFactory\$cgroup
string bool $cgroup
Definition: CommandFactory.php:39
MediaWiki\Shell
Copyright (C) 2017 Kunal Mehta legoktm@member.fsf.org
Definition: Command.php:21
ExecutableFinder\findInDefaultPaths
static findInDefaultPaths( $names, $versionInfo=false)
Same as locateExecutable(), but checks in getPossibleBinPaths() by default.
Definition: ExecutableFinder.php:96
MediaWiki\Shell\CommandFactory\findFirejail
findFirejail()
Definition: CommandFactory.php:77
MediaWiki\Shell\CommandFactory\create
create()
Instantiates a new Command.
Definition: CommandFactory.php:100