vendor/api-platform/core/src/Core/Bridge/Symfony/Bundle/DataProvider/TraceableChainCollectionDataProvider.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DataProvider;
  12. use ApiPlatform\Core\DataProvider\ChainCollectionDataProvider;
  13. use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
  14. use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
  15. use ApiPlatform\Core\DataProvider\RestrictDataProviderTrait;
  16. use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
  17. use ApiPlatform\Exception\ResourceClassNotSupportedException;
  18. /**
  19.  * @author Anthony GRASSIOT <antograssiot@free.fr>
  20.  */
  21. final class TraceableChainCollectionDataProvider implements ContextAwareCollectionDataProviderInterfaceRestrictedDataProviderInterface
  22. {
  23.     use RestrictDataProviderTrait;
  24.     private $context = [];
  25.     private $providersResponse = [];
  26.     public function __construct(CollectionDataProviderInterface $collectionDataProvider)
  27.     {
  28.         if ($collectionDataProvider instanceof ChainCollectionDataProvider) {
  29.             $this->dataProviders $collectionDataProvider->dataProviders;
  30.         }
  31.     }
  32.     public function getProvidersResponse(): array
  33.     {
  34.         return $this->providersResponse;
  35.     }
  36.     public function getContext(): array
  37.     {
  38.         return $this->context;
  39.     }
  40.     public function getCollection(string $resourceClassstring $operationName null, array $context = []): iterable
  41.     {
  42.         $this->context $context;
  43.         $results null;
  44.         $match false;
  45.         foreach ($this->dataProviders as $dataProvider) {
  46.             $this->providersResponse[\get_class($dataProvider)] = $match null false;
  47.             if ($match) {
  48.                 continue;
  49.             }
  50.             try {
  51.                 if ($dataProvider instanceof RestrictedDataProviderInterface
  52.                     && !$dataProvider->supports($resourceClass$operationName$context)) {
  53.                     continue;
  54.                 }
  55.                 $results $dataProvider->getCollection($resourceClass$operationName$context);
  56.                 $this->providersResponse[\get_class($dataProvider)] = $match true;
  57.             } catch (ResourceClassNotSupportedException $e) {
  58.                 @trigger_error(sprintf('Throwing a "%s" in a data provider is deprecated in favor of implementing "%s"'ResourceClassNotSupportedException::class, RestrictedDataProviderInterface::class), \E_USER_DEPRECATED);
  59.                 continue;
  60.             }
  61.         }
  62.         return $results ?? [];
  63.     }
  64. }