MediaWiki  REL1_20
StubObject.php
Go to the documentation of this file.
00001 <?php
00038 class StubObject {
00039         var $mGlobal, $mClass, $mParams;
00040 
00049         function __construct( $global = null, $class = null, $params = array() ) {
00050                 $this->mGlobal = $global;
00051                 $this->mClass = $class;
00052                 $this->mParams = $params;
00053         }
00054 
00062         static function isRealObject( $obj ) {
00063                 return is_object( $obj ) && !($obj instanceof StubObject);
00064         }
00065 
00077         function _call( $name, $args ) {
00078                 $this->_unstub( $name, 5 );
00079                 return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args );
00080         }
00081 
00086         function _newObject() {
00087                 return MWFunction::newObj( $this->mClass, $this->mParams );
00088         }
00089 
00098         function __call( $name, $args ) {
00099                 return $this->_call( $name, $args );
00100         }
00101 
00112         function _unstub( $name = '_unstub', $level = 2 ) {
00113                 static $recursionLevel = 0;
00114 
00115                 if ( !($GLOBALS[$this->mGlobal] instanceof StubObject) ) {
00116                         return $GLOBALS[$this->mGlobal]; // already unstubbed.
00117                 }
00118 
00119                 if ( get_class( $GLOBALS[$this->mGlobal] ) != $this->mClass ) {
00120                         $fname = __METHOD__.'-'.$this->mGlobal;
00121                         wfProfileIn( $fname );
00122                         $caller = wfGetCaller( $level );
00123                         if ( ++$recursionLevel > 2 ) {
00124                                 throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" );
00125                         }
00126                         wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}::$name from $caller\n" );
00127                         $GLOBALS[$this->mGlobal] = $this->_newObject();
00128                         --$recursionLevel;
00129                         wfProfileOut( $fname );
00130                 }
00131         }
00132 }
00133 
00140 class StubContLang extends StubObject {
00141 
00142         function __construct() {
00143                 wfDeprecated( __CLASS__, '1.18' );
00144                 parent::__construct( 'wgContLang' );
00145         }
00146 
00147         function __call( $name, $args ) {
00148                 return $this->_call( $name, $args );
00149         }
00150 
00154         function _newObject() {
00155                 global $wgLanguageCode;
00156                 $obj = Language::factory( $wgLanguageCode );
00157                 $obj->initEncoding();
00158                 $obj->initContLang();
00159                 return $obj;
00160         }
00161 }
00162 
00168 class StubUserLang extends StubObject {
00169 
00170         function __construct() {
00171                 parent::__construct( 'wgLang' );
00172         }
00173 
00174         function __call( $name, $args ) {
00175                 return $this->_call( $name, $args );
00176         }
00177 
00181         function _newObject() {
00182                 return RequestContext::getMain()->getLanguage();
00183         }
00184 }