Example #1
0
    protected function scan(array $tokens)
    {
        $annotations     = array();
        $annotationIndex = -1;
        $contentEnd      = false;

        reset($tokens);

        SCANNER_TOP:
        $token = current($tokens);

        switch ($token[0]) {

            case 'ANNOTATION_CLASS':

                $contentEnd = false;
                $annotationIndex++;
                $class                         = substr($token[1], 1);
                $class                         = $this->nameInformation->resolveName($class);
                $annotations[$annotationIndex] = array($class, null);
                goto SCANNER_CONTINUE;

            case 'ANNOTATION_CONTENT_START':

                $annotations[$annotationIndex][1] = '';

            case 'ANNOTATION_CONTENT_END':
            case 'ANNOTATION_CONTENT':
            case 'ANNOTATION_WHITESPACE':
            case 'ANNOTATION_NEWLINE':

                if (!$contentEnd && isset($annotations[$annotationIndex]) && is_string($annotations[$annotationIndex][1])) {
                    $annotations[$annotationIndex][1] .= $token[1];
                }

                if ($token[0] === 'ANNOTATION_CONTENT_END') {
                    $contentEnd = true;
                }

                goto SCANNER_CONTINUE;
        }

        SCANNER_CONTINUE:
        if (next($tokens) === false) {
            goto SCANNER_END;
        }
        goto SCANNER_TOP;

        SCANNER_END:

        foreach ($annotations as $annotation) {
            if ($this->annotationManager->hasAnnotation($annotation[0])) {
                $this->append(
                    $this->annotationManager->createAnnotation($annotation[0], trim($annotation[1], '()'))
                );
            }
        }
    }
Example #2
0
 public function testManagerAllowsPassingArrayOfAnnotationInstancesToConstructor()
 {
     $manager = new Annotation\AnnotationManager(array(new TestAsset\Foo(), new TestAsset\Bar()));
     $this->assertTrue($manager->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo'));
     $this->assertTrue($manager->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Bar'));
 }