| @@ 23-54 (lines=32) @@ | ||
| 20 | * |
|
| 21 | * @author Kévin Dunglas <[email protected]> |
|
| 22 | */ |
|
| 23 | final class ChainCollectionDataProvider implements CollectionDataProviderInterface |
|
| 24 | { |
|
| 25 | private $dataProviders; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @param CollectionDataProviderInterface[] $dataProviders |
|
| 29 | */ |
|
| 30 | public function __construct(array $dataProviders) |
|
| 31 | { |
|
| 32 | $this->dataProviders = $dataProviders; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * {@inheritdoc} |
|
| 37 | */ |
|
| 38 | public function getCollection(string $resourceClass, string $operationName = null) |
|
| 39 | { |
|
| 40 | foreach ($this->dataProviders as $dataProvider) { |
|
| 41 | try { |
|
| 42 | if ($dataProvider instanceof RestrictedDataProviderInterface |
|
| 43 | && !$dataProvider->supports($resourceClass, $operationName)) { |
|
| 44 | continue; |
|
| 45 | } |
|
| 46 | ||
| 47 | return $dataProvider->getCollection($resourceClass, $operationName); |
|
| 48 | } catch (ResourceClassNotSupportedException $e) { |
|
| 49 | @trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED); |
|
| 50 | continue; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||
| @@ 23-53 (lines=31) @@ | ||
| 20 | * |
|
| 21 | * @author Kévin Dunglas <[email protected]> |
|
| 22 | */ |
|
| 23 | final class ChainItemDataProvider implements ItemDataProviderInterface |
|
| 24 | { |
|
| 25 | private $dataProviders; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @param ItemDataProviderInterface[] $dataProviders |
|
| 29 | */ |
|
| 30 | public function __construct(array $dataProviders) |
|
| 31 | { |
|
| 32 | $this->dataProviders = $dataProviders; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * {@inheritdoc} |
|
| 37 | */ |
|
| 38 | public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) |
|
| 39 | { |
|
| 40 | foreach ($this->dataProviders as $dataProvider) { |
|
| 41 | try { |
|
| 42 | if ($dataProvider instanceof RestrictedDataProviderInterface |
|
| 43 | && !$dataProvider->supports($resourceClass, $operationName)) { |
|
| 44 | continue; |
|
| 45 | } |
|
| 46 | ||
| 47 | return $dataProvider->getItem($resourceClass, $id, $operationName, $context); |
|
| 48 | } catch (ResourceClassNotSupportedException $e) { |
|
| 49 | @trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED); |
|
| 50 | continue; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||