コード例 #1
0
 /**
  * @param Stmt $classStmt
  * @param $namespace
  * @param $source
  * @return Element\ClassModel
  */
 public function parse(Stmt $classStmt, $namespace, $source)
 {
     $attrs = $classStmt->getAttributes();
     $class = $this->classFactory->create($classStmt->name);
     $class->setNamespace($namespace);
     $class->setSource($source, $attrs['startLine'], 0);
     // annotation
     $this->commentsParser->parse($attrs, $class);
     // property
     $properties = array_filter($classStmt->stmts, function ($stmt) {
         return $this->propertyParser->match($stmt);
     });
     array_map(function (Stmt $propertiesStmt) use($class) {
         $prop = $this->propertyParser->parse($propertiesStmt, $class);
         $this->propertyAnnotationParser->parse($propertiesStmt, $prop, $class);
         $varAnnotations = $prop->annotations->withName('var');
         if (!$varAnnotations->isEmpty()) {
             /** @var Element\Annotation $var */
             $var = $varAnnotations->first();
             $prop->setAccessModifier($var->parameters);
         }
     }, $properties);
     // method
     $methods = array_filter($classStmt->stmts, function ($stmt) {
         return $this->methodParser->match($stmt);
     });
     array_map(function ($methodStmt) use($class) {
         $this->methodParser->parse($methodStmt, $class);
     }, $methods);
     return $class;
 }
コード例 #2
0
 /**
  * @param Stmt $propertyStmt
  * @param Element\Property $property
  * @param Element\ClassModel $class
  * @return Element\Annotation\AnnotationCollection
  */
 public function parse(Stmt $propertyStmt, Element\Property $property, Element\ClassModel $class)
 {
     // annotation
     $attrs = $propertyStmt->getAttributes();
     $this->commentsParser->parse($attrs, $property);
     $vars = $property->annotations->withName('var');
     if ($vars->count()) {
         /** @var Element\Annotation $var */
         $var = $vars->first();
         if (!is_array($var->parameters)) {
             // classのuseにあるものだけにする(FQCN形式等は要検討)
             //  型が単純なクラス名ではなくて Element\Annotation のような形式になっている場合は、Element 部分が use にあればOK
             if ($searchAlias = strstr($var->parameters, '\\', true) === false) {
                 $searchAlias = $var->parameters;
             }
             $classReferences = $class->references->withAlias($searchAlias);
             if ($classReferences->count()) {
                 $ref = $this->referenceFactory->create($var->parameters, null);
                 $property->reference = $ref;
             }
         }
     }
     return $property->annotations;
 }