MediaWiki REL1_40
|
Class to implement stub globals, which are globals that delay loading the their associated module code by deferring initialisation until the first method call. More...
Inherited by MediaWiki\StubObject\DeprecatedGlobal, MediaWiki\StubObject\StubGlobalUser, and MediaWiki\StubObject\StubUserLang.
Public Member Functions | |
__call ( $name, $args) | |
Function called by PHP if no function with that name exists in this object. | |
__construct ( $global=null, $class=null, $params=[]) | |
__get ( $name) | |
Function called by PHP if no property with that name exists in this object. | |
__set ( $name, $value) | |
Function called by PHP if no property with that name exists in this object. | |
_call ( $name, $args) | |
Function called if any function exists with that name in this object. | |
_get ( $name) | |
Wrapper for __get(), similar to _call() above. | |
_newObject () | |
Create a new object to replace this stub object. | |
_set ( $name, $value) | |
Wrapper for __set(), similar to _call() above. | |
_unstub ( $name='_unstub', $level=2) | |
This function creates a new object of the real class and replace it in the global variable. | |
Static Public Member Functions | |
static | isRealObject ( $obj) |
Returns a bool value whenever $obj is a stub object. | |
static | unstub (&$obj) |
Unstubs an object, if it is a stub object. | |
Protected Attributes | |
null string | $class |
null callable | $factory |
null string | $global |
array | $params |
Class to implement stub globals, which are globals that delay loading the their associated module code by deferring initialisation until the first method call.
Note on reference parameters:
If the called method takes any parameters by reference, the __call magic here won't work correctly. The solution is to unstub the object before calling the method.
Note on unstub loops:
Unstub loops (infinite recursion) sometimes occur when a constructor calls another function, and the other function calls some method of the stub. The best way to avoid this is to make constructors as lightweight as possible, deferring any initialisation which depends on other modules. As a last resort, you can use MediaWiki\StubObject\StubObject::isRealObject() to break the loop, but as a general rule, the stub object mechanism should be transparent, and code which refers to it should be kept to a minimum.
Definition at line 55 of file StubObject.php.
MediaWiki\StubObject\StubObject::__construct | ( | $global = null, | |
$class = null, | |||
$params = [] ) |
string | null | $global | Name of the global variable. |
string | callable | null | $class | Name of the class of the real object or a factory function to call |
array | $params | Parameters to pass to constructor of the real object. |
Reimplemented in MediaWiki\StubObject\DeprecatedGlobal.
Definition at line 76 of file StubObject.php.
References MediaWiki\StubObject\StubObject\$class, MediaWiki\StubObject\StubObject\$global, and MediaWiki\StubObject\StubObject\$params.
MediaWiki\StubObject\StubObject::__call | ( | $name, | |
$args ) |
Function called by PHP if no function with that name exists in this object.
string | $name | Name of the function called |
array | $args | Arguments |
Definition at line 154 of file StubObject.php.
References MediaWiki\StubObject\StubObject\_call().
MediaWiki\StubObject\StubObject::__get | ( | $name | ) |
Function called by PHP if no property with that name exists in this object.
string | $name | Name of the property to get |
Definition at line 177 of file StubObject.php.
References MediaWiki\StubObject\StubObject\_get().
MediaWiki\StubObject\StubObject::__set | ( | $name, | |
$value ) |
Function called by PHP if no property with that name exists in this object.
string | $name | Name of the property to set |
mixed | $value | New property value |
Definition at line 200 of file StubObject.php.
References MediaWiki\StubObject\StubObject\_set().
MediaWiki\StubObject\StubObject::_call | ( | $name, | |
$args ) |
Function called if any function exists with that name in this object.
It is used to unstub the object. Only used internally, PHP will call self::__call() function and that function will call this function. This function will also call the function with the same name in the real object.
string | $name | Name of the function called |
array | $args | Arguments |
Definition at line 123 of file StubObject.php.
References MediaWiki\StubObject\StubObject\_unstub().
Referenced by MediaWiki\StubObject\StubObject\__call().
MediaWiki\StubObject\StubObject::_get | ( | $name | ) |
Wrapper for __get(), similar to _call() above.
string | $name | Name of the property to get |
Definition at line 165 of file StubObject.php.
References MediaWiki\StubObject\StubObject\$global, and MediaWiki\StubObject\StubObject\_unstub().
Referenced by MediaWiki\StubObject\StubObject\__get().
MediaWiki\StubObject\StubObject::_newObject | ( | ) |
Create a new object to replace this stub object.
Reimplemented in MediaWiki\StubObject\DeprecatedGlobal, MediaWiki\StubObject\StubGlobalUser, and MediaWiki\StubObject\StubUserLang.
Definition at line 133 of file StubObject.php.
References MediaWiki\StubObject\StubObject\$class, MediaWiki\StubObject\StubObject\$factory, and MediaWiki\StubObject\StubObject\$params.
Referenced by MediaWiki\StubObject\StubObject\_unstub().
MediaWiki\StubObject\StubObject::_set | ( | $name, | |
$value ) |
Wrapper for __set(), similar to _call() above.
string | $name | Name of the property to set |
mixed | $value | New property value |
Definition at line 188 of file StubObject.php.
References MediaWiki\StubObject\StubObject\$global, and MediaWiki\StubObject\StubObject\_unstub().
Referenced by MediaWiki\StubObject\StubObject\__set().
MediaWiki\StubObject\StubObject::_unstub | ( | $name = '_unstub', | |
$level = 2 ) |
This function creates a new object of the real class and replace it in the global variable.
This is public, for the convenience of external callers wishing to access properties, e.g. eval.php
string | $name | Name of the method called in this object. |
int | $level | Level to go in the stack trace to get the function who called this function. |
MWException |
Reimplemented in MediaWiki\StubObject\StubGlobalUser.
Definition at line 217 of file StubObject.php.
References MediaWiki\StubObject\StubObject\$global, MediaWiki\StubObject\StubObject\_newObject(), wfDebug(), and wfGetCaller().
Referenced by MediaWiki\StubObject\StubObject\_call(), MediaWiki\StubObject\StubObject\_get(), and MediaWiki\StubObject\StubObject\_set().
|
static |
Returns a bool value whenever $obj is a stub object.
Can be used to break a infinite loop when unstubbing an object.
object | $obj | Object to check. |
Definition at line 93 of file StubObject.php.
|
static |
Unstubs an object, if it is a stub object.
Can be used to break a infinite loop when unstubbing an object or to avoid reference parameter breakage.
object | &$obj | Object to check. |
Definition at line 105 of file StubObject.php.
|
protected |
Definition at line 60 of file StubObject.php.
Referenced by MediaWiki\StubObject\StubObject\__construct(), and MediaWiki\StubObject\StubObject\_newObject().
|
protected |
Definition at line 63 of file StubObject.php.
Referenced by MediaWiki\StubObject\StubObject\_newObject().
|
protected |
Definition at line 57 of file StubObject.php.
Referenced by MediaWiki\StubObject\StubObject\__construct(), MediaWiki\StubObject\StubObject\_get(), MediaWiki\StubObject\StubObject\_set(), and MediaWiki\StubObject\StubObject\_unstub().
|
protected |
Definition at line 66 of file StubObject.php.
Referenced by MediaWiki\StubObject\StubObject\__construct(), and MediaWiki\StubObject\StubObject\_newObject().