MediaWiki REL1_30
StubObject.php
Go to the documentation of this file.
1<?php
46 protected $global;
47
49 protected $class;
50
52 protected $factory;
53
55 protected $params;
56
63 public function __construct( $global = null, $class = null, $params = [] ) {
64 $this->global = $global;
65 if ( is_callable( $class ) ) {
66 $this->factory = $class;
67 } else {
68 $this->class = $class;
69 }
70 $this->params = $params;
71 }
72
80 public static function isRealObject( $obj ) {
81 return is_object( $obj ) && !$obj instanceof StubObject;
82 }
83
92 public static function unstub( &$obj ) {
93 if ( $obj instanceof StubObject ) {
94 $obj = $obj->_unstub( 'unstub', 3 );
95 }
96 }
97
109 public function _call( $name, $args ) {
110 $this->_unstub( $name, 5 );
111 return call_user_func_array( [ $GLOBALS[$this->global], $name ], $args );
112 }
113
118 public function _newObject() {
119 $params = $this->factory
120 ? [ 'factory' => $this->factory ]
121 : [ 'class' => $this->class ];
122 return ObjectFactory::getObjectFromSpec( $params + [
123 'args' => $this->params,
124 'closure_expansion' => false,
125 ] );
126 }
127
136 public function __call( $name, $args ) {
137 return $this->_call( $name, $args );
138 }
139
152 public function _unstub( $name = '_unstub', $level = 2 ) {
153 static $recursionLevel = 0;
154
155 if ( !$GLOBALS[$this->global] instanceof StubObject ) {
156 return $GLOBALS[$this->global]; // already unstubbed.
157 }
158
159 if ( get_class( $GLOBALS[$this->global] ) != $this->class ) {
160 $caller = wfGetCaller( $level );
161 if ( ++$recursionLevel > 2 ) {
162 throw new MWException( "Unstub loop detected on call of "
163 . "\${$this->global}->$name from $caller\n" );
164 }
165 wfDebug( "Unstubbing \${$this->global} on call of "
166 . "\${$this->global}::$name from $caller\n" );
168 --$recursionLevel;
169 return $GLOBALS[$this->global];
170 }
171 }
172}
173
178
179 public function __construct() {
180 parent::__construct( 'wgLang' );
181 }
182
195 public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
196 global $wgLang;
197 $this->_unstub( 'findVariantLink', 3 );
198 $wgLang->findVariantLink( $link, $nt, $ignoreOtherCond );
199 }
200
204 public function _newObject() {
205 return RequestContext::getMain()->getLanguage();
206 }
207}
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
Definition Autoload.php:10
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...
if( $line===false) $args
Definition cdb.php:63
MediaWiki exception.
static getMain()
Static methods.
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.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition design.txt:56
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2989