From 15d464c5b7182eb4c7a9e1b0180f6fe46401ed22 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 22 Nov 2005 22:06:04 +0000 Subject: --- framework/core.php | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'framework') diff --git a/framework/core.php b/framework/core.php index 9dd43e76..02d771db 100644 --- a/framework/core.php +++ b/framework/core.php @@ -426,33 +426,46 @@ class PradoBase * or a namespace referring to the path of the component class file. * For example, 'TButton', 'System.Web.UI.WebControls.TButton' are both * valid component type. + * This method can also pass parameters to component constructors. + * All paramters passed to this method except the first one (the component type) + * will be supplied as component constructor paramters. * @param string component type * @return TComponent component instance of the specified type * @throws TInvalidDataValueException if the component type is unknown */ public static function createComponent($type) { - if(class_exists($type,false)) - return new $type; - if(($pos=strrpos($type,'.'))===false) - { - include_once($type.self::CLASS_FILE_EXT); - if(class_exists($type,false)) - return new $type; - } - else + if(!class_exists($type,false)) { - $className=substr($type,$pos+1); - if(class_exists($className,false)) - return new $className; - else if(($path=self::getPathOfNamespace($type))!==null) + if(($pos=strrpos($type,'.'))===false) { - include_once($path.self::CLASS_FILE_EXT); - if(class_exists($className,false)) - return new $className; + include_once($type.self::CLASS_FILE_EXT); + if(!class_exists($type,false)) + throw new TInvalidDataValueException('prado_component_unknown',$type); } + else + { + $className=substr($type,$pos+1); + if(!class_exists($className,false) && ($path=self::getPathOfNamespace($type))!==null) + { + include_once($path.self::CLASS_FILE_EXT); + if(!class_exists($className,false)) + throw new TInvalidDataValueException('prado_component_unknown',$type); + } + $type=$className; + } + } + if(($n=func_num_args())>1) + { + $args=func_get_args(); + $s='$args[1]'; + for($i=2;$i<$n;++$i) + $s.=",\$args[$i]"; + eval("\$component=new $type($s);"); + return $component; } - throw new TInvalidDataValueException('prado_component_unknown',$type); + else + return new $type; } /** -- cgit v1.2.3