summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-01-21 16:03:19 +0000
committerxue <>2006-01-21 16:03:19 +0000
commit99b56c855a597c606d349c7063d843539e65a6ed (patch)
tree0f5b2c8451d84895f49eee42cb73baa10ee7ebd6
parentdd76d0c2cfa3425c2e8dad54f2bcb12148957db5 (diff)
Enhanced Prado::using().
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/config.xml2
-rw-r--r--demos/quickstart/protected/pages/Fundamentals/Samples/config.xml2
-rw-r--r--framework/Exceptions/messages.txt1
-rw-r--r--framework/core.php87
4 files changed, 42 insertions, 50 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Samples/config.xml b/demos/quickstart/protected/pages/Controls/Samples/config.xml
index ecd29bd4..51da9ed0 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/config.xml
+++ b/demos/quickstart/protected/pages/Controls/Samples/config.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
- <pages MasterClass="Controls.SampleLayout" />
+ <pages MasterClass="SampleLayout" />
</configuration> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml b/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml
index ecd29bd4..51da9ed0 100644
--- a/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml
+++ b/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
- <pages MasterClass="Controls.SampleLayout" />
+ <pages MasterClass="SampleLayout" />
</configuration> \ No newline at end of file
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index f3d741cb..fd33596b 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -3,6 +3,7 @@ prado_component_unknown = Unable to create unknown component '%s'.
prado_using_invalid = '%s' is not a valid namespace to be used. Make sure '.*' is appended if you want to use a namespace referring to a directory.
prado_alias_redefined = Alias '%s' cannot be redefined.
prado_alias_invalid = Alias '%s' refers to an invalid path '%s'. Only existing directories can be aliased.
+prado_aliasname_invalid = Alias '%s' contains invalid character '.'.
component_property_undefined = Component property '%s.%s' is not defined.
component_property_readonly = Component property '%s.%s' is read-only.
diff --git a/framework/core.php b/framework/core.php
index cbb53ddc..97b5c9dc 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -469,7 +469,7 @@ class PradoBase
/**
* Serializes a data.
- * Original PHP serialize function has a bug that may not serialize
+ * The original PHP serialize function has a bug that may not serialize
* properly an object.
* @param mixed data to be serialized
* @return string the serialized data
@@ -482,7 +482,7 @@ class PradoBase
/**
* Unserializes a data.
- * Original PHP unserialize function has a bug that may not unserialize
+ * The original PHP unserialize function has a bug that may not unserialize
* properly an object.
* @param string data to be unserialized
* @return mixed unserialized data, null if unserialize failed
@@ -508,26 +508,9 @@ class PradoBase
*/
public static function createComponent($type)
{
- if(!class_exists($type,false))
- {
- if(($pos=strrpos($type,'.'))===false)
- {
- include_once($type.self::CLASS_FILE_EXT);
- if(!class_exists($type,false))
- throw new TInvalidOperationException('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 TInvalidOperationException('prado_component_unknown',$type);
- }
- $type=$className;
- }
- }
+ self::using($type);
+ if(($pos=strrpos($type,'.'))!==false)
+ $type=substr($type,$pos+1);
if(($n=func_num_args())>1)
{
$args=func_get_args();
@@ -551,35 +534,41 @@ class PradoBase
*/
public static function using($namespace)
{
- if(!isset(self::$_usings[$namespace]))
+ if(isset(self::$_usings[$namespace]) || class_exists($namespace,false))
+ return;
+ if(($pos=strrpos($namespace,'.'))===false) // a class name
{
- if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))===null)
- throw new TInvalidDataValueException('prado_using_invalid',$namespace);
- else
+ require_once($namespace.self::CLASS_FILE_EXT);
+ if(!class_exists($namespace,false))
+ throw new TInvalidOperationException('prado_component_unknown',$namespace);
+ }
+ else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null)
+ {
+ $className=substr($namespace,$pos+1);
+ if($className==='*') // a directory
{
- if($namespace[strlen($namespace)-1]==='*') // a directory
+ if(is_dir($path))
{
- if(is_dir($path))
- {
- self::$_usings[$namespace]=$path;
- set_include_path(get_include_path().PATH_SEPARATOR.$path);
- }
- else
- throw new TInvalidDataValueException('prado_using_invalid',$namespace);
+ self::$_usings[$namespace]=$path;
+ set_include_path(get_include_path().PATH_SEPARATOR.$path);
}
- else // a file
+ else
+ throw new TInvalidDataValueException('prado_using_invalid',$namespace);
+ }
+ else // a file
+ {
+ if(is_file($path))
{
- if(is_file($path))
- {
- self::$_usings[$namespace]=$path;
- if(!class_exists(substr(strrchr($namespace,'.'),1),false))
- require_once($path);
- }
- else
- throw new TInvalidDataValueException('prado_using_invalid',$namespace);
+ self::$_usings[$namespace]=$path;
+ if(!class_exists($className,false))
+ require_once($path);
}
+ else
+ throw new TInvalidDataValueException('prado_using_invalid',$namespace);
}
}
+ else
+ throw new TInvalidDataValueException('prado_using_invalid',$namespace);
}
/**
@@ -617,10 +606,7 @@ class PradoBase
*/
public static function getPathOfAlias($alias)
{
- if(isset(self::$_aliases[$alias]))
- return self::$_aliases[$alias];
- else
- return null;
+ return isset(self::$_aliases[$alias])?self::$_aliases[$alias]:null;
}
/**
@@ -634,7 +620,12 @@ class PradoBase
if(isset(self::$_aliases[$alias]))
throw new TInvalidOperationException('prado_alias_redefined',$alias);
else if(($rp=realpath($path))!==false && is_dir($rp))
- self::$_aliases[$alias]=$rp;
+ {
+ if(strpos($alias,'.')===false)
+ self::$_aliases[$alias]=$rp;
+ else
+ throw new TInvalidDataValueException('prado_aliasname_invalid',$alias);
+ }
else
throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path);
}