MediaWiki REL1_33
StubObject.php
Go to the documentation of this file.
1<?php
22use Wikimedia\ObjectFactory;
23
47 protected $global;
48
50 protected $class;
51
53 protected $factory;
54
56 protected $params;
57
64 public function __construct( $global = null, $class = null, $params = [] ) {
65 $this->global = $global;
66 if ( is_callable( $class ) ) {
67 $this->factory = $class;
68 } else {
69 $this->class = $class;
70 }
71 $this->params = $params;
72 }
73
81 public static function isRealObject( $obj ) {
82 return is_object( $obj ) && !$obj instanceof StubObject;
83 }
84
93 public static function unstub( &$obj ) {
94 if ( $obj instanceof StubObject ) {
95 $obj = $obj->_unstub( 'unstub', 3 );
96 }
97 }
98
110 public function _call( $name, $args ) {
111 $this->_unstub( $name, 5 );
112 return call_user_func_array( [ $GLOBALS[$this->global], $name ], $args );
113 }
114
119 public function _newObject() {
120 $params = $this->factory
121 ? [ 'factory' => $this->factory ]
122 : [ 'class' => $this->class ];
123 return ObjectFactory::getObjectFromSpec( $params + [
124 'args' => $this->params,
125 'closure_expansion' => false,
126 ] );
127 }
128
137 public function __call( $name, $args ) {
138 return $this->_call( $name, $args );
139 }
140
153 public function _unstub( $name = '_unstub', $level = 2 ) {
154 static $recursionLevel = 0;
155
156 if ( !$GLOBALS[$this->global] instanceof StubObject ) {
157 return $GLOBALS[$this->global]; // already unstubbed.
158 }
159
160 if ( get_class( $GLOBALS[$this->global] ) != $this->class ) {
161 $caller = wfGetCaller( $level );
162 if ( ++$recursionLevel > 2 ) {
163 throw new MWException( "Unstub loop detected on call of "
164 . "\${$this->global}->$name from $caller\n" );
165 }
166 wfDebug( "Unstubbing \${$this->global} on call of "
167 . "\${$this->global}::$name from $caller\n" );
168 $GLOBALS[$this->global] = $this->_newObject();
170 return $GLOBALS[$this->global];
171 }
172 }
173}
174
179
180 public function __construct() {
181 parent::__construct( 'wgLang' );
182 }
183
196 public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
197 global $wgLang;
198 $this->_unstub( 'findVariantLink', 3 );
199 $wgLang->findVariantLink( $link, $nt, $ignoreOtherCond );
200 }
201
205 public function _newObject() {
206 return RequestContext::getMain()->getLanguage();
207 }
208}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$GLOBALS['IP']
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
$wgLang
Definition Setup.php:875
if( $line===false) $args
Definition cdb.php:64
MediaWiki exception.
Class to implement stub globals, which are globals that delay loading the their associated module cod...
_unstub( $name='_unstub', $level=2)
This function creates a new object of the real class and replace it in the global variable.
null string $global
_call( $name, $args)
Function called if any function exists with that name in this object.
null callable $factory
array $params
static unstub(&$obj)
Unstubs an object, if it is a stub object.
_newObject()
Create a new object to replace this stub object.
null string $class
__construct( $global=null, $class=null, $params=[])
__call( $name, $args)
Function called by PHP if no function with that name exists in this object.
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
Stub object for the user language.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
Call Language::findVariantLink after unstubbing $wgLang.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3069
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params