Beispiel #1
0
 /**
  * Generate documentation with the name and version.
  *
  * @param string $name
  * @param string $version
  *
  * @return bool
  */
 public function generate(Collection $controllers, $name, $version)
 {
     $resources = $controllers->map(function ($controller) use($version) {
         $controller = $controller instanceof ReflectionClass ? $controller : new ReflectionClass($controller);
         $actions = new Collection();
         // Spin through all the methods on the controller and compare the version
         // annotation (if supplied) with the version given for the generation.
         // We'll also build up an array of actions on each resource.
         foreach ($controller->getMethods() as $method) {
             if ($versionAnnotation = $this->reader->getMethodAnnotation($method, Annotation\Versions::class)) {
                 if (!in_array($version, $versionAnnotation->value)) {
                     continue;
                 }
             }
             if ($annotations = $this->reader->getMethodAnnotations($method)) {
                 if (!$actions->contains($method)) {
                     $actions->push(new Action($method, new Collection($annotations)));
                 }
             }
         }
         $annotations = new Collection($this->reader->getClassAnnotations($controller));
         return new Resource($controller->getName(), $controller, $annotations, $actions);
     });
     return $this->generateContentsFromResources($resources, $name);
 }
 /**
  * @param type $class
  * @return \Nucleus\Annotation\IParsingResult
  */
 public function parse($className)
 {
     $reflectionClass = new \ReflectionClass($className);
     $result = new ParsingResult($reflectionClass->getName());
     $result->setClassAnnotations($this->reader->getClassAnnotations($reflectionClass));
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $result->setMethodAnnotations($reflectionMethod->getName(), $this->reader->getMethodAnnotations($reflectionMethod));
     }
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $result->setMethodAnnotations($reflectionMethod->getName(), $this->reader->getMethodAnnotations($reflectionMethod));
     }
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         $result->setPropertyAnnotations($reflectionProperty->getName(), $this->reader->getPropertyAnnotations($reflectionProperty));
     }
     $parentClass = $reflectionClass->getParentClass();
     if ($parentClass) {
         $parentResult = $this->parse($parentClass->getName());
         $result->mergeParentClass($parentResult);
     }
     $interfaceClasses = $reflectionClass->getInterfaces();
     foreach ($interfaceClasses as $interfaceClass) {
         /* @var $interfaceClass \ReflectionClass  */
         $interfaceResult = $this->parse($interfaceClass->getName());
         $result->mergeParentClass($interfaceResult);
     }
     return $result;
 }
Beispiel #3
0
 public function testIssueSimpleAnnotationReader()
 {
     $reader = new SimpleAnnotationReader();
     $reader->addNamespace('Doctrine\\Tests\\Common\\Annotations\\Ticket\\Doctrine\\ORM\\Mapping');
     $annots = $reader->getClassAnnotations(new \ReflectionClass(__NAMESPACE__ . "\\MappedClass"));
     $this->assertEquals(1, count($annots));
     $this->assertInstanceOf("Doctrine\\Tests\\Common\\Annotations\\Ticket\\Doctrine\\ORM\\Mapping\\Entity", $annots[0]);
 }
Beispiel #4
0
 /**
  * @return array
  */
 private function getAnnotations($base)
 {
     $baseAnnots = $this->annotReader->getClassAnnotations(new \ReflectionClass($base));
     $extended = $this->extendableResolveClassName($base);
     if ($base == $extended) {
         return $this->mergeAnnots($baseAnnots);
     }
     // fetch annotations of the extended class and merge them with the annotions
     // of the base one
     $extendedAnnots = $this->annotReader->getClassAnnotations(new \ReflectionClass($extended));
     return $this->mergeAnnots($baseAnnots, $extendedAnnots);
 }
 /**
  * Create a new annotation set instance.
  *
  * @param  \ReflectionClass  $class
  * @param  \Doctrine\Common\Annotations\SimpleAnnotationReader  $reader
  * @return void
  */
 public function __construct(ReflectionClass $class, SimpleAnnotationReader $reader)
 {
     $this->class = $reader->getClassAnnotations($class);
     $this->method = $this->getMethodAnnotations($class, $reader);
 }
 protected function getDomainObjectAnnotations()
 {
     $reader = new SimpleAnnotationReader();
     $reader->addNamespace('Oneup\\AclBundle\\Mapping\\Annotation');
     $object = new \ReflectionClass('Oneup\\AclBundle\\Tests\\Model\\SomeObject');
     return $reader->getClassAnnotations($object);
 }