Example #1
0
 /**
  * Factory depuis une reflection
  *
  * @param ReflectionProperty $reflection
  * @return static
  */
 public static function fromReflection(ReflectionProperty $reflection)
 {
     // gestion du type
     $type = implode('|', $reflection->getDocBlockTypeStrings());
     // cas de la valeur null
     $value = $reflection->getDefaultValue();
     if (is_null($value)) {
         $value = Maker::NO_VALUE;
         $class = $reflection->getDeclaringClass();
         foreach ($class->getAst()->stmts as $stmt) {
             // si pas un attribut, on zap
             if (!$stmt instanceof \PhpParser\Node\Stmt\Property) {
                 continue;
             }
             foreach ($stmt->props as $prop) {
                 if ($prop instanceof \PhpParser\Node\Stmt\PropertyProperty) {
                     // lecture du fichier
                     $file = file($class->getFileName());
                     if (!empty($line = $file[$prop->getLine() - 1])) {
                         if (strpos($line, '=')) {
                             $value = null;
                         }
                     }
                 }
             }
         }
     }
     // construction
     $property = new static($reflection->getName(), $value, $type);
     // docblock
     $docblock = new \phpDocumentor\Reflection\DocBlock($reflection->getDocComment());
     $property->setSummary($docblock->getShortDescription());
     $property->setDescription($docblock->getLongDescription());
     // gestion des modifiers
     $reflection->isPrivate() ? $property->enablePrivate() : $property->disablePrivate();
     $reflection->isProtected() ? $property->enableProtected() : $property->disabledProtected();
     $reflection->isPublic() ? $property->enablePublic() : $property->disablePublic();
     $reflection->isStatic() ? $property->enableStatic() : $property->disableStatic();
     return $property;
 }
Example #2
0
 /**
  *
  *
  * @param ReflectionMethod $reflection
  * @return Method
  */
 public static function fromReflection(ReflectionMethod $reflection)
 {
     // gestion du type
     //       $type = implode('|', $reflection->getDocBlockTypeStrings());
     //
     // construction
     $method = new static($reflection->getName(), [], $reflection->getBodyCode());
     // docblock
     $docblock = new \phpDocumentor\Reflection\DocBlock($reflection->getDocComment());
     $method->setSummary($docblock->getShortDescription());
     $method->setDescription($docblock->getLongDescription());
     // gestion des modifiers
     $reflection->isPrivate() ? $method->enablePrivate() : $method->disablePrivate();
     $reflection->isProtected() ? $method->enableProtected() : $method->disabledProtected();
     $reflection->isPublic() ? $method->enablePublic() : $method->disablePublic();
     $reflection->isStatic() ? $method->enableStatic() : $method->disableStatic();
     $reflection->isFinal() ? $method->enableFinal() : $method->disableFinal();
     foreach ($reflection->getParameters() as $parameter) {
         $method->addParameter(Parameter::fromReflection($parameter));
     }
     return $method;
 }