MediaWiki REL1_32
shell.php
Go to the documentation of this file.
1<?php
40
41require_once __DIR__ . '/Maintenance.php';
42
48
49 public function __construct() {
50 parent::__construct();
51 $this->addOption( 'd',
52 'For back compatibility with eval.php. ' .
53 '1 send debug to stderr. ' .
54 'With 2 additionally initialize database with debugging ',
55 false, true
56 );
57 }
58
59 public function execute() {
60 if ( !class_exists( \Psy\Shell::class ) ) {
61 $this->fatalError( 'PsySH not found. Please run composer with the --dev option.' );
62 }
63
64 $traverser = new \PhpParser\NodeTraverser();
65 $codeCleaner = new \Psy\CodeCleaner( null, null, $traverser );
66
67 // add this after initializing the code cleaner so all the default passes get added first
68 $traverser->addVisitor( new CodeCleanerGlobalsPass() );
69
70 $config = new \Psy\Configuration();
71 $config->setCodeCleaner( $codeCleaner );
72 $config->setUpdateCheck( \Psy\VersionUpdater\Checker::NEVER );
73 // prevent https://github.com/bobthecow/psysh/issues/443 when using sudo -E
74 $config->setRuntimeDir( wfTempDir() );
75
76 $shell = new \Psy\Shell( $config );
77 if ( $this->hasOption( 'd' ) ) {
78 $this->setupLegacy();
79 }
80
81 $shell->run();
82 }
83
87 protected function setupLegacy() {
88 $d = intval( $this->getOption( 'd' ) );
89 if ( $d > 0 ) {
90 LoggerFactory::registerProvider( new ConsoleSpi );
91 // Some services hold Logger instances in object properties
92 MediaWikiServices::resetGlobalInstance();
93 }
94 if ( $d > 1 ) {
95 # Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
96 wfGetDB( DB_MASTER )->setFlag( DBO_DEBUG );
97 wfGetDB( DB_REPLICA )->setFlag( DBO_DEBUG );
98 }
99 }
100
101}
102
103$maintClass = MediaWikiShell::class;
104require_once RUN_MAINTENANCE_IF_MAIN;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfTempDir()
Tries to get the system directory for temporary files.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Prefix the real command with a bunch of 'global $VAR;' commands, one for each global.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular option exists.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Config $config
Accessible via getConfig()
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Interactive shell with completion and global scope.
Definition shell.php:47
execute()
Do the actual work.
Definition shell.php:59
setupLegacy()
For back compatibility with eval.php.
Definition shell.php:87
__construct()
Default constructor.
Definition shell.php:49
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
const DBO_DEBUG
Definition defines.php:9
$maintClass
Definition shell.php:103