ApiPlatform\Core\DataProvider\ChainCollectionDataProvider::getCollection PHP Method

getCollection() public method

public getCollection ( string $resourceClass, string $operationName = null )
$resourceClass string
$operationName string
    public function getCollection(string $resourceClass, string $operationName = null)
    {
        foreach ($this->dataProviders as $dataProvider) {
            try {
                return $dataProvider->getCollection($resourceClass, $operationName);
            } catch (ResourceClassNotSupportedException $e) {
                continue;
            }
        }
    }

Usage Example

 public function testGetCollectionExeptions()
 {
     $firstDataProvider = $this->prophesize(CollectionDataProviderInterface::class);
     $firstDataProvider->getCollection('notfound', 1)->willThrow(ResourceClassNotSupportedException::class);
     $chainItemDataProvider = new ChainCollectionDataProvider([$firstDataProvider->reveal()]);
     $this->assertEquals('', $chainItemDataProvider->getCollection('notfound', 1));
 }
ChainCollectionDataProvider