ApiPlatform\Core\DataProvider\ChainItemDataProvider::getItem PHP Method

getItem() public method

public getItem ( string $resourceClass, $id, string $operationName = null, array $context = [] )
$resourceClass string
$operationName string
$context array
    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
    {
        foreach ($this->dataProviders as $dataProviders) {
            try {
                return $dataProviders->getItem($resourceClass, $id, $operationName, $context);
            } catch (ResourceClassNotSupportedException $e) {
                continue;
            }
        }
    }

Usage Example

 public function testGetItemExeptions()
 {
     $firstDataProvider = $this->prophesize(ItemDataProviderInterface::class);
     $firstDataProvider->getItem('notfound', 1, null, [])->willThrow(ResourceClassNotSupportedException::class);
     $chainItemDataProvider = new ChainItemDataProvider([$firstDataProvider->reveal()]);
     $this->assertEquals('', $chainItemDataProvider->getItem('notfound', 1));
 }
ChainItemDataProvider