diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Web/UI/TTemplateManager.php | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 75f6268f..843331e9 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -684,6 +684,7 @@ class TTemplate extends TApplicationComponent implements ITemplate $className=substr($type,$pos+1);
else
$className=$type;
+ $class=new TReflectionClass($className);
if(is_subclass_of($className,'TControl') || $className==='TControl')
{
foreach($attributes as $name=>$att)
@@ -692,13 +693,13 @@ class TTemplate extends TApplicationComponent implements ITemplate {
// a subproperty, so the first segment must be readable
$subname=substr($name,0,$pos);
- if(!is_callable(array($className,'get'.$subname)))
+ if(!$class->containsMethod('get'.$subname))
throw new TConfigurationException('template_property_unknown',$type,$subname);
}
else if(strncasecmp($name,'on',2)===0)
{
// an event
- if(!is_callable(array($className,$name)))
+ if(!$class->containsMethod($name))
throw new TConfigurationException('template_event_unknown',$type,$name);
else if(!is_string($att))
throw new TConfigurationException('template_eventhandler_invalid',$type,$name);
@@ -706,9 +707,9 @@ class TTemplate extends TApplicationComponent implements ITemplate else
{
// a simple property
- if(!is_callable(array($className,'set'.$name)))
+ if(!$class->containsMethod('set'.$name))
{
- if(is_callable(array($className,'get'.$name)))
+ if($class->containsMethod('get'.$name))
throw new TConfigurationException('template_property_readonly',$type,$name);
else
throw new TConfigurationException('template_property_unknown',$type,$name);
@@ -726,7 +727,7 @@ class TTemplate extends TApplicationComponent implements ITemplate {
// a subproperty, so the first segment must be readable
$subname=substr($name,0,$pos);
- if(!is_callable(array($className,'get'.$subname)))
+ if(!$class->containsMethod('get'.$subname))
throw new TConfigurationException('template_property_unknown',$type,$subname);
}
else if(strncasecmp($name,'on',2)===0)
@@ -734,9 +735,9 @@ class TTemplate extends TApplicationComponent implements ITemplate else
{
// id is still alowed for TComponent, even if id property doesn't exist
- if(strcasecmp($name,'id')!==0 && !is_callable(array($className,'set'.$name)))
+ if(strcasecmp($name,'id')!==0 && !$class->containsMethod('set'.$name))
{
- if(is_callable(array($className,'get'.$name)))
+ if($class->containsMethod('get'.$name))
throw new TConfigurationException('template_property_readonly',$type,$name);
else
throw new TConfigurationException('template_property_unknown',$type,$name);
@@ -749,4 +750,33 @@ class TTemplate extends TApplicationComponent implements ITemplate }
}
+/**
+ * TReflectionClass class.
+ * This class is written to cope with the incompatibility between 5.1+ and earlier versions.
+ * It mainly provides a way to detect if a method exists for a given class name.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TReflectionClass extends ReflectionClass
+{
+ /**
+ * @param string method name
+ * @return boolean whether the method exists
+ */
+ public function containsMethod($method)
+ {
+ try
+ {
+ return $this->getMethod($method)!==null;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
+}
+
?>
\ No newline at end of file |