/** * @test */ public function test_parse_method_annotation() { $intf = new \ReflectionClass(TodoDao2::class); $commentParser = new AnnotationConverterAdapter($intf); listByPub: $annotations = $commentParser->getMethodAnnotations($intf->getMethod('listByPub')); $this->assertCount(4, $annotations); $this->assertInstanceOf(Select::class, $annotations[0]); $this->assertInstanceOf(ParamAlt::class, $annotations[1]); $this->assertEquals(\DateTime::class, $annotations[1]->type); $this->assertEquals('from', $annotations[1]->name); $this->assertInstanceOf(ParamAlt::class, $annotations[2]); $this->assertEquals(\DateTime::class, $annotations[2]->type); $this->assertEquals('to', $annotations[2]->name); $this->assertInstanceOf(Returning::class, $annotations[3]); $this->assertEquals(Todo::class . '[]', $annotations[3]->type); Hidden: $intf = new \ReflectionClass(Hidden::class); $commentParser = new AnnotationConverterAdapter($intf); $annotations = $commentParser->getMethodAnnotations($intf->getConstructor()); $this->assertCount(2, $annotations); $this->assertInstanceOf(Alias::class, $annotations[0]); $this->assertEquals('value', $annotations[0]->name); $this->assertEquals(['state'], $annotations[0]->alias); $this->assertInstanceOf(ParamAlt::class, $annotations[1]); $this->assertEquals('integer', $annotations[1]->type); $this->assertEquals('value', $annotations[1]->name); }
public function parseAsDomain($type, CaseSensor $sensor, $hasName) { $ref = new \ReflectionClass($type); $reader = new AnnotationConverterAdapter($ref); $ctor = $ref->getConstructor(); $annotations = $reader->getMethodAnnotations($ctor); $domains = $this->parseParamDomain($ctor->getParameters(), $annotations, $sensor); if (!$hasName) { return new WrappedDomain($type, array_values($domains)); } else { $aliases = array_reduce($this->extractAnnotations($annotations, Alias::class), function (array &$tmp, Alias $a) { return $tmp + [$a->name => $a->alias]; }, []); $domains = array_reduce(array_keys($domains), function (array &$tmp, $name) use($ref, $reader, $domains, $aliases, $sensor) { /* if (($m = $this->findGetterMethod($ref, $name)) === false) { $alias = $default = null; } else { $annotations = $reader->getMethodAnnotations($m); list($alias, $default) = $this->extractAnnotation( $annotations, Column::class, function ($a) { return [ $a->alias, $a->default ]; } ); } */ $k = $sensor->convert($name); return $tmp + [$k => new NamedAliasDomain($domains[$name], $k, isset($aliases[$name]) ? $this->convertNames($aliases[$name], $sensor) : [], null)]; }, []); return new WrappedDomain($type, $domains); } }
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]]; }, []); }