MediaWiki
REL1_24
|
00001 <?php 00044 class StubObject { 00046 protected $global; 00047 00049 protected $class; 00050 00052 protected $params; 00053 00061 public function __construct( $global = null, $class = null, $params = array() ) { 00062 $this->global = $global; 00063 $this->class = $class; 00064 $this->params = $params; 00065 } 00066 00074 public static function isRealObject( $obj ) { 00075 return is_object( $obj ) && !$obj instanceof StubObject; 00076 } 00077 00086 public static function unstub( &$obj ) { 00087 if ( $obj instanceof StubObject ) { 00088 $obj = $obj->_unstub( 'unstub', 3 ); 00089 } 00090 } 00091 00103 public function _call( $name, $args ) { 00104 $this->_unstub( $name, 5 ); 00105 return call_user_func_array( array( $GLOBALS[$this->global], $name ), $args ); 00106 } 00107 00112 public function _newObject() { 00113 return MWFunction::newObj( $this->class, $this->params ); 00114 } 00115 00124 public function __call( $name, $args ) { 00125 return $this->_call( $name, $args ); 00126 } 00127 00140 public function _unstub( $name = '_unstub', $level = 2 ) { 00141 static $recursionLevel = 0; 00142 00143 if ( !$GLOBALS[$this->global] instanceof StubObject ) { 00144 return $GLOBALS[$this->global]; // already unstubbed. 00145 } 00146 00147 if ( get_class( $GLOBALS[$this->global] ) != $this->class ) { 00148 $fname = __METHOD__ . '-' . $this->global; 00149 wfProfileIn( $fname ); 00150 $caller = wfGetCaller( $level ); 00151 if ( ++$recursionLevel > 2 ) { 00152 wfProfileOut( $fname ); 00153 throw new MWException( "Unstub loop detected on call of " 00154 . "\${$this->global}->$name from $caller\n" ); 00155 } 00156 wfDebug( "Unstubbing \${$this->global} on call of " 00157 . "\${$this->global}::$name from $caller\n" ); 00158 $GLOBALS[$this->global] = $this->_newObject(); 00159 --$recursionLevel; 00160 wfProfileOut( $fname ); 00161 return $GLOBALS[$this->global]; 00162 } 00163 } 00164 } 00165 00171 class StubUserLang extends StubObject { 00172 00173 public function __construct() { 00174 parent::__construct( 'wgLang' ); 00175 } 00176 00177 public function __call( $name, $args ) { 00178 return $this->_call( $name, $args ); 00179 } 00180 00184 public function _newObject() { 00185 return RequestContext::getMain()->getLanguage(); 00186 } 00187 }