Example #1
0
 private function reflect()
 {
     $class = new TReflectionClass($this->_className);
     $properties = array();
     $events = array();
     $methods = array();
     $isComponent = is_subclass_of($this->_className, 'TComponent') || strcasecmp($this->_className, 'TComponent') === 0;
     foreach ($class->getMethods() as $method) {
         if ($method->isPublic() || $method->isProtected()) {
             $methodName = $method->getName();
             if (!$method->isStatic() && $isComponent) {
                 if ($this->isPropertyMethod($method)) {
                     $properties[substr($methodName, 3)] = $method;
                 } else {
                     if ($this->isEventMethod($method)) {
                         $methodName[0] = 'O';
                         $events[$methodName] = $method;
                     }
                 }
             }
             if (strncmp($methodName, '__', 2) !== 0) {
                 $methods[$methodName] = $method;
             }
         }
     }
     $reserved = array();
     ksort($properties);
     foreach ($properties as $name => $method) {
         $this->_properties[$name] = array('type' => $this->determinePropertyType($method), 'readonly' => !$class->hasMethod('set' . $name), 'protected' => $method->isProtected(), 'class' => $method->getDeclaringClass()->getName(), 'comments' => $method->getDocComment());
         $reserved['get' . strtolower($name)] = 1;
         $reserved['set' . strtolower($name)] = 1;
     }
     ksort($events);
     foreach ($events as $name => $method) {
         $this->_events[$name] = array('class' => $method->getDeclaringClass()->getName(), 'protected' => $method->isProtected(), 'comments' => $method->getDocComment());
         $reserved[strtolower($name)] = 1;
     }
     ksort($methods);
     foreach ($methods as $name => $method) {
         if (!isset($reserved[strtolower($name)])) {
             $this->_methods[$name] = array('class' => $method->getDeclaringClass()->getName(), 'protected' => $method->isProtected(), 'static' => $method->isStatic(), 'comments' => $method->getDocComment());
         }
     }
 }
 protected function validateAttributes($type, $attributes)
 {
     Prado::using($type);
     if (($pos = strrpos($type, '.')) !== false) {
         $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) {
             if (($pos = strpos($name, '.')) !== false) {
                 $subname = substr($name, 0, $pos);
                 if (!$class->hasMethod('get' . $subname)) {
                     throw new TConfigurationException('template_property_unknown', $type, $subname);
                 }
             } else {
                 if (strncasecmp($name, 'on', 2) === 0) {
                     if (!$class->hasMethod($name)) {
                         throw new TConfigurationException('template_event_unknown', $type, $name);
                     } else {
                         if (!is_string($att)) {
                             throw new TConfigurationException('template_eventhandler_invalid', $type, $name);
                         }
                     }
                 } else {
                     if (!$class->hasMethod('set' . $name)) {
                         if ($class->hasMethod('get' . $name)) {
                             throw new TConfigurationException('template_property_readonly', $type, $name);
                         } else {
                             throw new TConfigurationException('template_property_unknown', $type, $name);
                         }
                     } else {
                         if (is_array($att) && $att[0] !== self::CONFIG_EXPRESSION) {
                             if (strcasecmp($name, 'id') === 0) {
                                 throw new TConfigurationException('template_controlid_invalid', $type);
                             } else {
                                 if (strcasecmp($name, 'skinid') === 0) {
                                     throw new TConfigurationException('template_controlskinid_invalid', $type);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         if (is_subclass_of($className, 'TComponent') || $className === 'TComponent') {
             foreach ($attributes as $name => $att) {
                 if (is_array($att) && $att[0] === self::CONFIG_DATABIND) {
                     throw new TConfigurationException('template_databind_forbidden', $type, $name);
                 }
                 if (($pos = strpos($name, '.')) !== false) {
                     $subname = substr($name, 0, $pos);
                     if (!$class->hasMethod('get' . $subname)) {
                         throw new TConfigurationException('template_property_unknown', $type, $subname);
                     }
                 } else {
                     if (strncasecmp($name, 'on', 2) === 0) {
                         throw new TConfigurationException('template_event_forbidden', $type, $name);
                     } else {
                         if (strcasecmp($name, 'id') !== 0 && !$class->hasMethod('set' . $name)) {
                             if ($class->hasMethod('get' . $name)) {
                                 throw new TConfigurationException('template_property_readonly', $type, $name);
                             } else {
                                 throw new TConfigurationException('template_property_unknown', $type, $name);
                             }
                         }
                     }
                 }
             }
         } else {
             throw new TConfigurationException('template_component_required', $type);
         }
     }
 }