ApiPlatform\Core\Bridge\NelmioApiDoc\Parser\ApiPlatformParser::supports PHP Method

supports() public method

public supports ( array $item )
$item array
    public function supports(array $item)
    {
        $data = explode(':', $item['class'], 3);
        if (!in_array($data[0], [self::IN_PREFIX, self::OUT_PREFIX])) {
            return false;
        }
        if (!isset($data[1])) {
            return false;
        }
        try {
            $this->resourceMetadataFactory->create($data[1]);
            return true;
        } catch (ResourceClassNotFoundException $e) {
            // return false
        }
        return false;
    }

Usage Example

 public function testSupportsUnsupportedClassFormat()
 {
     $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
     $resourceMetadataFactoryProphecy->create(Argument::any())->shouldNotBeCalled();
     $resourceMetadataFactory = $resourceMetadataFactoryProphecy->reveal();
     $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
     $propertyNameCollectionFactory = $propertyNameCollectionFactoryProphecy->reveal();
     $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $propertyMetadataFactory = $propertyMetadataFactoryProphecy->reveal();
     $apiPlatformParser = new ApiPlatformParser($resourceMetadataFactory, $propertyNameCollectionFactory, $propertyMetadataFactory);
     $this->assertFalse($apiPlatformParser->supports(['class' => Dummy::class]));
 }