/** * Finds the class annotations */ private function findAnnotations() { foreach (AnnotatedReflection::reader()->getClassAnnotations($this) as $index => $annotation) { $this->annotations[$index] = $annotation; } if ($parent = $this->getParentClass()) { if ($annotations = $parent->getAnnotations()) { $this->annotations = array_merge($annotations, $this->annotations); } } foreach (parent::getProperties() as $property) { foreach (AnnotatedReflection::reader()->getPropertyAnnotations($property) as $index => $annotation) { $this->property_annotations[$property->getName()][$index] = $annotation; } } foreach ($this->property_annotations as $name => $annotations) { foreach ($annotations as $index => $annotation) { $this->annotated_properties[$index][$name] = $this->createAnnotatedProperty($name); } } foreach (parent::getMethods() as $method) { foreach (AnnotatedReflection::reader()->getMethodAnnotations($method) as $index => $annotation) { $this->method_annotations[$method->getName()][$index] = $annotation; } } foreach ($this->method_annotations as $name => $annotations) { foreach ($annotations as $index => $annotation) { $this->annotated_methods[$index][$name] = $this->createAnnotatedMethod($name); } } }
/** * @covers ::reader */ public function testReader() { $this->assertInstanceOf(Reader::class, AnnotatedReflection::reader()); $this->assertSame(AnnotatedReflection::reader(), AnnotatedReflection::reader()); }
<?php namespace Headzoo\Reflection\Tests; use Headzoo\Reflection\AnnotatedReflection; use Headzoo\Reflection\Annotation\Headzoo; use Headzoo\Reflection\Annotation\Headzoo\Integer; use Headzoo\Reflection\Annotation\Headzoo\Method; use Headzoo\Reflection\Annotation\Headzoo\Property; use Headzoo\Reflection\Annotation\Headzoo\TestClass; use Headzoo\Reflection\Annotation\Headzoo\TestPerson; AnnotatedReflection::registerAnnotations([Integer::class, Method::class, Property::class, TestPerson::class, TestClass::class]); /** * @Headzoo\TestPerson("headzoo", job="code_monkey") */ class ParentPerson { /** * @Headzoo\Property * @Headzoo\Integer */ public $id; /** * @Headzoo\Integer * @Headzoo\Method */ public function getId() { } } /**
/** * Finds the class annotations */ private function findAnnotations() { foreach (AnnotatedReflection::reader()->getPropertyAnnotations($this) as $index => $annotation) { $this->annotations[$index] = $annotation; } }