getAnnotationsOfType() публичный Метод

public getAnnotationsOfType ( string $class, boolean $strict = false ) : array
$class string
$strict boolean Innon-strict mode childclasses are also detected.
Результат array
Пример #1
0
    public function testCleanUnmergedProcessor()
    {
        $comment = <<<END
@SWG\\Info(
    title="Info only has one contact field.",
    version="test",
)
@SWG\\License(
    name="MIT",
    @SWG\\Contact(
        name="Batman"
    )
)

END;
        $analysis = new Analysis($this->parseComment($comment));
        $this->assertCount(3, $analysis->annotations);
        $analysis->process(new MergeIntoSwagger());
        $this->assertCount(4, $analysis->annotations);
        $before = $analysis->split();
        $this->assertCount(2, $before->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info');
        $this->assertCount(2, $before->unmerged->annotations, '@SWG\\License + @SWG\\Contact');
        $this->assertCount(0, $analysis->swagger->_unmerged);
        $analysis->validate();
        // Validation fails to detect the unmerged annotations.
        // CleanUnmerged should place the unmerged annotions into the swagger->_unmerged array.
        $analysis->process(new CleanUnmerged());
        $between = $analysis->split();
        $this->assertCount(2, $between->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info');
        $this->assertCount(2, $between->unmerged->annotations, '@SWG\\License + @SWG\\Contact');
        $this->assertCount(2, $analysis->swagger->_unmerged);
        // 1 would also be oke, Could a'Only the @SWG\License'
        $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in ');
        $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\Contact(), expected to be inside @SWG\\Info in ');
        $analysis->validate();
        // When a processor places a previously unmerged annotation into the swagger obect.
        $license = $analysis->getAnnotationsOfType('Swagger\\Annotations\\License')[0];
        $contact = $analysis->getAnnotationsOfType('Swagger\\Annotations\\Contact')[0];
        $analysis->swagger->info->contact = $contact;
        $this->assertCount(1, $license->_unmerged);
        $analysis->process(new CleanUnmerged());
        $this->assertCount(0, $license->_unmerged);
        $after = $analysis->split();
        $this->assertCount(3, $after->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info + @SWG\\Contact');
        $this->assertCount(1, $after->unmerged->annotations, '@SWG\\License');
        $this->assertCount(1, $analysis->swagger->_unmerged);
        $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in ');
        $analysis->validate();
    }
Пример #2
0
 public function __invoke(Analysis $analysis)
 {
     $definitions = $analysis->getAnnotationsOfType('\\Swagger\\Annotations\\Definition');
     // Use the class names for @SWG\Definition()
     foreach ($definitions as $definition) {
         if ($definition->definition === null) {
             if ($definition->_context->is('class')) {
                 $definition->definition = $definition->_context->class;
             } elseif ($definition->_context->is('trait')) {
                 $definition->definition = $definition->_context->trait;
             }
             // if ($definition->type === null) {
             //     $definition->type = 'object';
             // }
         }
     }
     // Merge unmerged @SWG\Property annotations into the @SWG\Definition of the class
     $unmergedProperties = $analysis->unmerged()->getAnnotationsOfType('\\Swagger\\Annotations\\Property');
     foreach ($unmergedProperties as $property) {
         $definitonContext = $property->_context->with('class') ?: $property->_context->with('trait');
         if ($definitonContext->annotations) {
             $definition = false;
             foreach ($definitonContext->annotations as $annotation) {
                 if ($annotation instanceof Definition) {
                     $definition = $annotation;
                 }
             }
             if ($definition) {
                 $definition->merge([$property], true);
             }
         }
     }
 }
 public function __invoke(Analysis $analysis)
 {
     $schemas = $analysis->getAnnotationsOfType('\\Swagger\\Annotations\\Schema');
     foreach ($schemas as $schema) {
         if ($schema->_context->is('class')) {
             $existing = [];
             foreach ($schema->properties as $property) {
                 if ($property->property) {
                     $existing[] = $property->property;
                 }
             }
             $classes = $analysis->getSuperClasses($schema->_context->fullyQualifiedName($schema->_context->class));
             foreach ($classes as $class) {
                 foreach ($class['properties'] as $property) {
                     foreach ($property->annotations as $annotation) {
                         if ($annotation instanceof Property && in_array($annotation->property, $existing) === false) {
                             $existing[] = $annotation->property;
                             $schema->merge([$annotation], true);
                         }
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 public function __invoke(Analysis $analysis)
 {
     $refs = [];
     /** @var Definition $definition */
     foreach ($analysis->swagger->definitions as $definition) {
         if ($definition->definition) {
             $refs[strtolower($definition->_context->fullyQualifiedName($definition->_context->class))] = '#/definitions/' . $definition->definition;
         }
     }
     $allProperties = $analysis->getAnnotationsOfType('\\Swagger\\Annotations\\Property');
     /** @var \Swagger\Annotations\Property $property */
     foreach ($allProperties as $property) {
         $context = $property->_context;
         // Use the property names for @SWG\Property()
         if ($property->property === null) {
             $property->property = $context->property;
         }
         if (preg_match('/@var\\s+(?<type>[^\\s]+)([ \\t])?(?<description>.+)?$/im', $context->comment, $varMatches)) {
             if ($property->description === null && isset($varMatches['description'])) {
                 $property->description = trim($varMatches['description']);
             }
             if ($property->type === null) {
                 preg_match('/^([^\\[]+)(.*$)/', trim($varMatches['type']), $typeMatches);
                 $type = $typeMatches[1];
                 if (array_key_exists(strtolower($type), static::$types)) {
                     $type = static::$types[strtolower($type)];
                     if (is_array($type)) {
                         if ($property->format === null) {
                             $property->format = $type[1];
                         }
                         $type = $type[0];
                     }
                     $property->type = $type;
                 } elseif ($property->ref === null && $typeMatches[2] === '') {
                     $tmpKey = strtolower($context->fullyQualifiedName($type));
                     $property->ref = array_key_exists($tmpKey, $refs) ? $refs[$tmpKey] : null;
                 }
                 if ($typeMatches[2] === '[]') {
                     if ($property->items === null) {
                         $property->items = new Items(['type' => $property->type, '_context' => new Context(['generated' => true], $context)]);
                         if ($property->items->type === null) {
                             $tmpKey = strtolower($context->fullyQualifiedName($type));
                             $property->items->ref = array_key_exists($tmpKey, $refs) ? $refs[$tmpKey] : null;
                         }
                     }
                     $property->type = 'array';
                 }
             }
         }
         if ($property->description === null) {
             $property->description = $context->phpdocContent();
         }
     }
 }
Пример #5
0
 public function __invoke(Analysis $analysis)
 {
     $allOperations = $analysis->getAnnotationsOfType('\\Swagger\\Annotations\\Operation');
     /** @var Operation $operation */
     foreach ($allOperations as $operation) {
         if (null === $operation->summary) {
             $operation->summary = $operation->_context->phpdocSummary();
         }
         if (null === $operation->description) {
             $operation->description = $operation->_context->phpdocDescription();
         }
     }
 }