summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgodzilla80@gmx.net <>2009-06-28 15:11:52 +0000
committergodzilla80@gmx.net <>2009-06-28 15:11:52 +0000
commit41b396132ea4fbd97c24831612b7b22e479e033d (patch)
tree7c5ec8ba5b4244aa84a2fbc9d243929f5fd5a4ef
parentfd633327593864328790d0d79039dc1ac1f2ed82 (diff)
Performance optimization in PradoBase::createComponent()
-rw-r--r--HISTORY1
-rw-r--r--framework/PradoBase.php47
2 files changed, 39 insertions, 9 deletions
diff --git a/HISTORY b/HISTORY
index d519e8aa..4e0fa458 100644
--- a/HISTORY
+++ b/HISTORY
@@ -9,6 +9,7 @@ ENH: Issue#176 - THttpResponse::writeFile() add additional parameters to take mo
BUG: TCallbackErrorHandler::displayException() force HTTP status "500 Internal Server Error" to ensure TCallbackOptions.ClientSide.OnFailure is raised (Yves)
ENH: TAssetManager: introduce protected property "Published" to allow subclasses access (Yves)
ENH: TFirePhpLogRoute: bypass to TBrowserLogRoute if headers already sent / php.ini (output_buffering=Off, implicit_flush=On) (Yves)
+EHN: Performance optimization in PradoBase::createComponent() (Yves)
Version 3.1.5 May 24, 2009
BUG: Issue#55 - TPropertyAccess.get and has don't recognize magic getter __get (Yves)
diff --git a/framework/PradoBase.php b/framework/PradoBase.php
index a08b54ba..b2d7b631 100644
--- a/framework/PradoBase.php
+++ b/framework/PradoBase.php
@@ -62,6 +62,11 @@ class PradoBase
private static $_logger=null;
/**
+ * @var array list of class exists checks
+ */
+ protected static $classExists = array();
+
+ /**
* @return string the version of Prado framework
*/
public static function getVersion()
@@ -226,17 +231,41 @@ class PradoBase
*/
public static function createComponent($type)
{
- self::using($type);
- if(($pos=strrpos($type,'.'))!==false)
- $type=substr($type,$pos+1);
+ if(!isset(self::$classExists[$type]))
+ self::$classExists[$type] = class_exists($type, false);
+
+ if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) {
+ self::using($type);
+ self::$classExists[$type] = class_exists($type, false);
+ }
+
+ if( ($pos = strrpos($type, '.')) !== false)
+ $type = substr($type,$pos+1);
+
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;
+ $args = func_get_args();
+ switch($n) {
+ case 2:
+ return new $type($args[1]);
+ break;
+ case 3:
+ return new $type($args[1], $args[2]);
+ break;
+ case 4:
+ return new $type($args[1], $args[2], $args[3]);
+ break;
+ case 5:
+ return new $type($args[1], $args[2], $args[3], $args[4]);
+ break;
+ default:
+ $s='$args[1]';
+ for($i=2;$i<$n;++$i)
+ $s.=",\$args[$i]";
+ eval("\$component=new $type($s);");
+ return $component;
+ break;
+ }
}
else
return new $type;