ApiPlatform\Core\Hydra\Serializer\CollectionNormalizer::supportsNormalization PHP Method

supportsNormalization() public method

public supportsNormalization ( $data, $format = null )
    public function supportsNormalization($data, $format = null)
    {
        return self::FORMAT === $format && (is_array($data) || $data instanceof \Traversable);
    }

Usage Example

 public function testSupportsNormalize()
 {
     $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
     $iriConvert = $this->prophesize(IriConverterInterface::class);
     $contextBuilder = $this->prophesize(ContextBuilderInterface::class);
     $contextBuilder->getResourceContextUri('Foo')->willReturn('/contexts/Foo');
     $iriConvert->getIriFromResourceClass('Foo')->willReturn('/foos');
     $normalizer = new CollectionNormalizer($contextBuilder->reveal(), $resourceClassResolverProphecy->reveal(), $iriConvert->reveal());
     $this->assertTrue($normalizer->supportsNormalization([], CollectionNormalizer::FORMAT));
     $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT));
     $this->assertFalse($normalizer->supportsNormalization([], 'xml'));
     $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml'));
 }