/** * @test */ public function test_parse_class_annotation() { TodoDao: $intf = new \ReflectionClass(TodoDao::class); $commentParser = new AnnotationConverterAdapter($intf); $annotations = $commentParser->getClassAnnotations(); $this->assertCount(1, $annotations); $this->assertInstanceOf(Dao::class, $annotations[0]); $this->assertEquals('', $annotations[0]->route); TodoDao2: $intf = new \ReflectionClass(TodoDao2::class); $commentParser = new AnnotationConverterAdapter($intf); $annotations = $commentParser->getClassAnnotations(); $this->assertCount(1, $annotations); $this->assertInstanceOf(Dao::class, $annotations[0]); $this->assertEquals('/', $annotations[0]->route); }
public function prepare() { $reader = new AnnotationReader(); $commentParser = new AnnotationConverterAdapter($this->intf); $annotations = $commentParser->getClassAnnotations(); $this->config = $this->extractDaoClassConfig($annotations); $this->seqHint = $this->extractAnnotation($annotations, SequenceHint::class); $this->methods = array_reduce($this->intf->getMethods(), function (array &$tmp, \ReflectionMethod $m) use($reader, $commentParser) { $attrs = $commentParser->getMethodAnnotations($m); $returnTypes = $this->parseReturning($this->extractAnnotation($attrs, AbstractCommandAnnotation::class)); return $tmp + [$m->name => ['name' => $m->name, 'type' => $this->extractAnnotation($attrs, DaoAnnotation::class), 'params' => $m->getParameters(), 'paramDomain' => $this->paramToDomain($m->getParameters(), $attrs, $reader), 'returnDomain' => $this->returningToDomain($returnTypes, $attrs, $reader), 'returnTypes' => $returnTypes]]; }, []); }
public function parseAsEntity(\ReflectionClass $ref, CaseSensor $sensor) { $reader = new AnnotationConverterAdapter($ref); $fields = array_reduce($ref->getProperties(), function (array &$tmp, \ReflectionProperty $f) use($reader, $sensor) { $annotations = $reader->getPropertyAnnotations($f); $columnType = $this->extractAnnotation($annotations, ColumnType::class, function ($a) { return $a->type; }); list($alias, $default, $optFields) = $this->extractAnnotation($annotations, Column::class, function ($a) { return [$a->name, $a->default, $a->optFields]; }); $domain = $this->parseInternal($f->name, $columnType, $sensor, false); $optFields = array_map(function ($name) use($sensor) { return $sensor->convert($name); }, $optFields !== null ? $optFields : []); return $tmp + [$f->name => new NamedAliasDomain($domain, $sensor->convert($f->name), $this->convertNames([$alias], $sensor), $default, array_flip($optFields))]; }, []); return new ObjectDomain($ref->name, $fields); }