Пример #1
0
 public function testIfWillExtractTopValues()
 {
     $model = new ModelWithTopValues();
     // Raw matcher for debug
     $reflection = new ReflectionAnnotatedProperty($model, 'straight');
     $matcher = new AnnotationsMatcher();
     $matcher->setPlugins(new MatcherConfig(['addendum' => new Addendum(), 'reflection' => $reflection]));
     $data = [];
     $comment = Addendum::getDocComment($reflection);
     $matcher->matches($comment, $data);
     $meta = Meta::create($model);
     // All fields have same annotation
     foreach ($meta->fields() as $fieldMeta) {
         $title = sprintf('Annotation is defined on %s', $fieldMeta->name);
         $this->assertSame(ModelWithTopValues::ClassValue, $fieldMeta->class);
         $this->assertSame(ModelWithTopValues::UpdatableValue, $fieldMeta->updatable);
     }
 }
Пример #2
0
    public function testIfWillRawMatchConstant()
    {
        $doc = <<<'DOC'
	/**
	 * @Label(ModelWithConstantLabel)
	 * @var string
	 */
DOC;
        $matcher = new AnnotationsMatcher();
        $matcher->setPlugins(new MatcherConfig(['addendum' => new Addendum(), 'reflection' => new ReflectionClass($this)]));
        $data = [];
        $matcher->matches($doc, $data);
        $this->assertSame(1, count($data));
        $this->assertSame(1, count($data['Label']));
        $this->assertSame(1, count($data['Label'][0]));
        $value = $data['Label'][0];
        $this->assertSame(ModelWithConstantLabel, $value['value']);
    }
    /**
     * Was not matching class literal with numbers, see maslosoft/addendum@ac22a08e01601208abae2bfd9b22c61adc461265
     */
    public function testIfMatcherWillMatch()
    {
        $doc = <<<'DOC'
	/**
	 * @SlotFor(Maslosoft\SignalsTest\Signals\MethodInjected)
	 * @SlotFor(Maslosoft\SignalsTest\Signals\MethodInjected2)
	 * @SignalFor(Blah)
	 * @param ISignal $signal
	 */
DOC;
        $parser = new AnnotationsMatcher();
        $parser->setPlugins(new MatcherConfig(['addendum' => new Addendum(), 'reflection' => new ReflectionClass($this)]));
        $data = [];
        $parser->matches($doc, $data);
        $this->assertSame(2, count($data));
        $this->assertSame(2, count($data['SlotFor']));
        $this->assertSame(1, count($data['SlotFor'][0]));
        $this->assertSame(1, count($data['SlotFor'][1]));
    }
Пример #4
0
 /**
  * Get doc comment
  * @param ReflectionAnnotatedClass|ReflectionAnnotatedMethod|ReflectionAnnotatedProperty $reflection
  * @return mixed[]
  */
 private function parse($reflection)
 {
     $key = sprintf('%s@%s', $this->addendum->getInstanceId(), ReflectionName::createName($reflection));
     if (!isset(self::$cache[$key])) {
         //
         if (!CoarseChecker::mightHaveAnnotations($reflection)) {
             self::$cache[$key] = [];
             return self::$cache[$key];
         }
         $parser = new AnnotationsMatcher();
         $data = [];
         $parser->setPlugins(new MatcherConfig(['addendum' => $this->addendum, 'reflection' => $reflection]));
         $parser->matches($this->getDocComment($reflection), $data);
         self::$cache[$key] = $data;
     }
     return self::$cache[$key];
 }
Пример #5
0
 /**
  * Annotate file without including php file and without using reflection.
  * This method returns raw annotation values.
  * <i>This is intented for various builders, which should not include files.</i>
  * This <b>ALWAYS</b> parses file.
  * @param string $file
  * @param string $className <b>NOT RECOMMENDED!</b> Optional class name if multiple classes are declared in one file
  * @return mixed[][]
  */
 public static function rawAnnotate($file, $className = null)
 {
     $docExtractor = new DocComment();
     $docs = $docExtractor->forFile($file, $className);
     $matcher = new AnnotationsMatcher();
     $class = [];
     $matcher->setPlugins(new MatcherConfig(['addendum' => new Addendum(), 'reflection' => new ReflectionFile($file)]));
     $matcher->matches($docs['class'], $class);
     $methods = [];
     foreach ((array) $docs['methods'] as $name => $doc) {
         $methods[$name] = [];
         $matcher->matches($doc, $methods[$name]);
     }
     $fields = [];
     foreach ((array) $docs['fields'] as $name => $doc) {
         $fields[$name] = [];
         $matcher->matches($doc, $fields[$name]);
     }
     $result = ['namespace' => $docs['namespace'], 'className' => $docs['className'], 'class' => $class, 'methods' => $methods, 'fields' => $fields];
     return $result;
 }