Project

General

Profile

Bug #20029 » makeInstanceWithArgs_v2.diff

Administrator Admin, 2009-02-19 13:31

View differences:

t3lib/class.t3lib_div.php (working copy)
}
// Get final classname
$className = t3lib_div::makeInstanceClassName($className);
$className = self::getClassName($className);
if (isset($instances[$className])) {
// it's a singleton, get the existing instance
$instance = $instances[$className];
} else {
$instance = new $className;
if (func_num_args() > 1) {
// removing the method's first argument (the class name)
$constructorArguments = func_get_args();
array_shift($constructorArguments);
$reflectionObject = new ReflectionClass($className);
$constructor = $reflectionObject->getConstructor();
if ($reflectionObject->getConstructor() instanceof ReflectionMethod) {
$instance = $reflectionObject->newInstanceArgs($constructorArguments);
} else {
$instance = $reflectionObject->newInstance();
}
} else {
$instance = new $className;
}
if ($instance instanceof t3lib_Singleton) {
// it's a singleton, save the instance for later reuse
$instances[$className] = $instance;
......
}
/**
* Return classname for new instance, takes the class-extensions API
* of TYPO3 into account.
*
* @param string Base Class name to evaluate
* @return string Final class name to instantiate with "new [classname]"
*/
protected function getClassName($className) {
return class_exists('ux_'.$className) ? self::getClassName('ux_'.$className) : $className;
}
/**
* Find the best service and check if it works.
* Returns object of the service class.
*
typo3/backend.php (working copy)
);
foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
// Get name of XCLASS (if any):
$toolbarItemClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
$toolbarItem = new $toolbarItemClassName($this);
$toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
if(!($toolbarItem instanceof backend_toolbarItem)) {
throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
(2-2/3)