示例#1
0
 public static function calculate_type($reflection)
 {
     $annotations = Annotation::parse($reflection);
     if (isset($annotations['type'])) {
         return $annotations['type'];
     } else {
         $defaults = $reflection->getDeclaringClass()->getDefaultProperties();
         $default_value = $defaults[$reflection->getName()];
         if (is_null($default_value)) {
             return 'null';
         }
         if (is_string($default_value)) {
             return 'string';
         } else {
             if (is_integer($default_value)) {
                 return 'integer';
             } else {
                 if (is_float($default_value)) {
                     return 'float';
                 } else {
                     if (is_bool($default_value)) {
                         return 'boolean';
                     } else {
                         if (is_array($default_value)) {
                             return 'array';
                         }
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public function execute($include_inherited_members = false)
 {
     if (!isset($this->_classes[0])) {
         throw new \Wave\Exception('No files to reflect on');
     }
     $classes = array();
     foreach ($this->_classes as $class) {
         $reflector = new \ReflectionClass($class);
         $class_annotations = Annotation::parse($reflector->getDocComment(), $class);
         $parent_class = $reflector->getParentClass();
         $c = array('name' => $class, 'subclasses' => $parent_class instanceof \ReflectionClass ? $parent_class->getName() : '', 'implements' => $reflector->getInterfaceNames(), 'annotations' => $class_annotations);
         $methods = array();
         foreach ($reflector->getMethods() as $method) {
             $declaring_class = $method->getDeclaringClass()->getName();
             // don't put inherited methods on here plz
             if ($declaring_class != $class && !$include_inherited_members) {
                 continue;
             }
             $annotations = Annotation::parse($method->getDocComment(), $class);
             $method_annotations = array();
             foreach ($annotations as $annotation) {
                 $method_annotations[] = $annotation;
             }
             $method_name = $method->getName();
             $visibility = $method->isPublic() ? self::VISIBILITY_PUBLIC : ($method->isPrivate() ? self::VISIBILITY_PRIVATE : self::VISIBILITY_PROTECTED);
             $methods[$method_name] = array('name' => $method_name, 'visibility' => $visibility, 'static' => $method->isStatic(), 'parameters' => $method->getParameters(), 'annotations' => $method_annotations, 'declaring_class' => $method->getDeclaringClass()->getName());
         }
         $properties = array();
         foreach ($reflector->getProperties() as $property) {
             $declaring_class = $property->getDeclaringClass()->getName();
             // don't put inherited methods on here plz
             if ($declaring_class != $class && !$include_inherited_members) {
                 continue;
             }
             $annotations = Annotation::parse($property->getDocComment(), $class);
             $property_annotations = array();
             foreach ($annotations as $annotation) {
                 $property_annotations[] = $annotation;
             }
             $property_name = $property->getName();
             $visibility = $property->isPublic() ? self::VISIBILITY_PUBLIC : ($property->isPrivate() ? self::VISIBILITY_PRIVATE : self::VISIBILITY_PROTECTED);
             $properties[$property_name] = array('name' => $property_name, 'visibility' => $visibility, 'static' => $property->isStatic(), 'annotations' => $property_annotations, 'declaring_class' => $property->getDeclaringClass()->getName());
         }
         $classes[$class] = array('class' => $c, 'methods' => $methods, 'properties' => $properties);
     }
     return $classes;
 }
 function getAnnotations()
 {
     $docstring = $this->getDocComment();
     if ($docstring == '') {
         return array();
     } else {
         $returns = array();
         try {
             $returns = Annotation::parse($docstring);
         } catch (InvalidAnnotationValueException $e) {
             throw new InvalidAnnotationValueException('In class "' . $this->getDeclaringClass()->name . '" on property "' . $this->name . '".' . $e->getMessage(), 0, 0, $this->getDeclaringClass()->getFileName(), $this->getDeclaringClass()->getStartLine(), array());
         } catch (UnknownAnnotationException $e) {
             throw new UnknownAnnotationException('In class "' . $this->getDeclaringClass()->name . '" on property "' . $this->name . '".' . $e->getMessage(), 0, 0, $this->getDeclaringClass()->getFileName(), $this->getDeclaringClass()->getStartLine(), array());
         }
     }
     return $returns;
 }
 function getAnnotations()
 {
     Library::import('recess.lang.Annotation');
     $docstring = $this->getDocComment();
     if ($docstring == '') {
         return array();
     } else {
         $returns = array();
         try {
             $returns = Annotation::parse($docstring);
         } catch (InvalidAnnotationValueException $e) {
             throw new InvalidAnnotationValueException('In class "' . $this->name . '".' . $e->getMessage(), 0, 0, $this->getFileName(), $this->getStartLine(), array());
         } catch (UnknownAnnotationException $e) {
             throw new UnknownAnnotationException('In class "' . $this->name . '".' . $e->getMessage(), 0, 0, $this->getFileName(), $this->getStartLine(), array());
         }
     }
     return $returns;
 }
示例#5
0
 private function handle_class($class)
 {
     $reflection = new \ReflectionClass($class);
     $annotations = Annotation::parse($reflection);
     if (isset($annotations['model'])) {
         echo "creating model {$reflection->getName()}\n";
         $model = new Model($this->universe, $reflection);
         $this->universe->register_model($model);
     }
 }
示例#6
0
 /**
  * Process a property
  * @param \ReflectionProperty $p
  */
 private function processProperty(\ReflectionProperty $p)
 {
     $registered = false;
     foreach (Annotation::parse($p->getDocComment()) as $a) {
         if ($a->getName() != "element" && $a->getName() != "attribute") {
             continue;
         }
         if ($p->isStatic()) {
             $this->fail("Static property '{$p->name}' cannot be serialized");
         }
         if (!$registered) {
             $p->setAccessible(true);
             $this->reflectors[$p->name] = $p;
             $registered = true;
         }
         $type = "";
         if ($a->getParamCount() > 0) {
             $type = $a->getParam(0);
         }
         $type = $this->resolveType($type);
         $xmlName = $p->name;
         if ($a->getParamCount() > 1) {
             $xmlName = $a->getParam(1);
         }
         $isElement = $a->getName() == "element";
         if ($this->hasXmlNameForProperty($p->name, $type)) {
             $this->fail("Duplicate xml name for property name '{$p->name}' and value type '{$type}'");
         }
         if (!array_key_exists($p->name, $this->props)) {
             $this->props[$p->name] = array();
         }
         $this->props[$p->name][$type] = array($xmlName, $isElement);
         if ($isElement) {
             if ($this->hasPropertyForElement($xmlName)) {
                 $this->fail("Duplicate element '{$xmlName}'");
             }
             $this->els[$xmlName] = array($p->name, $type);
         } else {
             if ($this->hasPropertyForAttribute($xmlName)) {
                 $this->fail("Duplicate attribute '{$xmlName}'");
             }
             $this->attrs[$xmlName] = array($p->name, $type);
         }
     }
 }
示例#7
0
    public function testParseNamespaced()
    {
        $comment = <<<'DOC'
/**
 * foobar
 *
 * @ORM\Column(type="string")
 */
DOC;
        $doc = Annotation::parse($comment);
        $this->assertEquals('(type="string")', $doc->getFirstAnnotation('Column'));
    }
示例#8
0
文件: Model.php 项目: jaz303/spitfire
 private function scan_serial()
 {
     foreach ($this->klass->getProperties() as $ref) {
         $annotations = Annotation::parse($ref);
         if (isset($annotations['serial'])) {
             if ($this->serial === null) {
                 $this->serial = $ref->getName();
             } else {
                 throw new Exception("only one serial field per model is supported");
             }
         }
     }
 }