public function testNewObjFunction()
 {
     $arg1 = 'Foo';
     $arg2 = 'Bar';
     $arg3 = array('Baz');
     $arg4 = new ExampleObject();
     $args = array($arg1, $arg2, $arg3, $arg4);
     $newObject = new MWBlankClass($arg1, $arg2, $arg3, $arg4);
     $this->assertEquals(MWFunction::newObj('MWBlankClass', $args)->args, $newObject->args);
 }
Exemple #2
0
 function testNewObjFunction()
 {
     $arg1 = 'Foo';
     $arg2 = 'Bar';
     $arg3 = array('Baz');
     $arg4 = new ExampleObject();
     $args = array($arg1, $arg2, $arg3, $arg4);
     $newObject = new MWBlankClass($arg1, $arg2, $arg3, $arg4);
     $this->assertEquals(MWFunction::newObj('MWBlankClass', $args)->args, $newObject->args);
     $this->assertEquals(MWFunction::newObj('MWBlankClass', $args, true)->args, $newObject->args, 'Works even with PHP version < 5.1.3');
 }
 /**
  * Find the object with a given name and return it (or NULL)
  *
  * @param $name String Special page name, may be localised and/or an alias
  * @return SpecialPage object or null if the page doesn't exist
  */
 public static function getPage($name)
 {
     list($realName, ) = self::resolveAlias($name);
     if (property_exists(self::getList(), $realName)) {
         $rec = self::getList()->{$realName};
         if (is_string($rec)) {
             $className = $rec;
             return new $className();
         } elseif (is_array($rec)) {
             // @deprecated, officially since 1.18, unofficially since forever
             wfDebug("Array syntax for \$wgSpecialPages is deprecated, define a subclass of SpecialPage instead.");
             $className = array_shift($rec);
             self::getList()->{$realName} = MWFunction::newObj($className, $rec);
         }
         return self::getList()->{$realName};
     } else {
         return null;
     }
 }
 /**
  * Create a new object to replace this stub object.
  * @return object
  */
 function _newObject()
 {
     return MWFunction::newObj($this->mClass, $this->mParams);
 }
/**
 * Create an object with a given name and an array of construct parameters
 *
 * @param $name String
 * @param $p Array: parameters
 * @deprecated since 1.18, warnings in 1.18, removal in 1.20
 */
function wfCreateObject($name, $p)
{
    wfDeprecated(__FUNCTION__);
    return MWFunction::newObj($name, $p);
}
Exemple #6
0
 /**
  * Create a new object to replace this stub object.
  * @return object
  */
 public function _newObject()
 {
     return MWFunction::newObj($this->class, $this->params);
 }
 /**
  * Find the object with a given name and return it (or NULL)
  *
  * @param string $name Special page name, may be localised and/or an alias
  * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
  */
 public static function getPage($name)
 {
     list($realName, ) = self::resolveAlias($name);
     $specialPageList = self::getPageList();
     if (isset($specialPageList[$realName])) {
         $rec = $specialPageList[$realName];
         if (is_callable($rec)) {
             // Use callback to instantiate the special page
             $page = call_user_func($rec);
         } elseif (is_string($rec)) {
             $className = $rec;
             $page = new $className();
         } elseif (is_array($rec)) {
             $className = array_shift($rec);
             // @deprecated, officially since 1.18, unofficially since forever
             wfDeprecated("Array syntax for \$wgSpecialPages is deprecated ({$className}), " . "define a subclass of SpecialPage instead.", '1.18');
             $page = MWFunction::newObj($className, $rec);
         } elseif ($rec instanceof SpecialPage) {
             $page = $rec;
             //XXX: we should deep clone here
         } else {
             $page = null;
         }
         if ($page instanceof SpecialPage) {
             return $page;
         } else {
             // It's not a classname, nor a callback, nor a legacy constructor array,
             // nor a special page object. Give up.
             wfLogWarning("Cannot instantiate special page {$realName}: bad spec!");
             return null;
         }
     } else {
         return null;
     }
 }
 /**
  * Find the object with a given name and return it (or NULL)
  *
  * @param string $name Special page name, may be localised and/or an alias
  * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
  */
 public static function getPage($name)
 {
     list($realName, ) = self::resolveAlias($name);
     $specialPageList = self::getList();
     if (isset($specialPageList[$realName])) {
         $rec = $specialPageList[$realName];
         if (is_string($rec)) {
             $className = $rec;
             return new $className();
         } elseif (is_array($rec)) {
             $className = array_shift($rec);
             // @deprecated, officially since 1.18, unofficially since forever
             wfDeprecated("Array syntax for \$wgSpecialPages is deprecated ({$className}), " . "define a subclass of SpecialPage instead.", '1.18');
             $specialPageList[$realName] = MWFunction::newObj($className, $rec);
         }
         return $specialPageList[$realName];
     } else {
         return null;
     }
 }