From bc1f23499f784618dba14694fe4261c3fb1cc81d Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 21 Feb 2006 04:49:09 +0000 Subject: Fixed an issue caused by the incompatibility of PHP 5.1.2 about is_callable(). --- framework/Web/UI/TTemplateManager.php | 44 +++++++++++++++++++++++++++++------ 1 file 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 + * @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 -- cgit v1.2.3