summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2005-11-22 22:06:04 +0000
committerxue <>2005-11-22 22:06:04 +0000
commit15d464c5b7182eb4c7a9e1b0180f6fe46401ed22 (patch)
tree318a957cab52e758eada9037f986d5701dc67543
parent233bda8e5ee36dd2d97af72caf2369de2aa271fe (diff)
-rw-r--r--framework/core.php47
1 files changed, 30 insertions, 17 deletions
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;
}
/**