vendor/api-platform/core/src/Core/Bridge/Symfony/Bundle/DataProvider/TraceableChainItemDataProvider.php line 56

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\ChainItemDataProvider;
  13. use ApiPlatform\Core\DataProvider\DenormalizedIdentifiersAwareItemDataProviderInterface;
  14. use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
  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 TraceableChainItemDataProvider implements ItemDataProviderInterfaceRestrictedDataProviderInterface
  22. {
  23.     use RestrictDataProviderTrait;
  24.     private $context = [];
  25.     private $providersResponse = [];
  26.     public function __construct(ItemDataProviderInterface $itemDataProvider)
  27.     {
  28.         if ($itemDataProvider instanceof ChainItemDataProvider) {
  29.             $this->dataProviders $itemDataProvider->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 getItem(string $resourceClass$idstring $operationName null, array $context = [])
  41.     {
  42.         $this->context $context;
  43.         $match false;
  44.         $result null;
  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.                 $identifier $id;
  56.                 if (!$dataProvider instanceof DenormalizedIdentifiersAwareItemDataProviderInterface && $identifier && \is_array($identifier)) {
  57.                     if (\count($identifier) > 1) {
  58.                         @trigger_error(sprintf('Receiving "$id" as non-array in an item data provider is deprecated in 2.3 in favor of implementing "%s".'DenormalizedIdentifiersAwareItemDataProviderInterface::class), \E_USER_DEPRECATED);
  59.                         $identifier http_build_query($identifier''';');
  60.                     } else {
  61.                         $identifier current($identifier);
  62.                     }
  63.                 }
  64.                 $result $dataProvider->getItem($resourceClass$identifier$operationName$context);
  65.                 $this->providersResponse[\get_class($dataProvider)] = $match true;
  66.             } catch (ResourceClassNotSupportedException $e) {
  67.                 @trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', \get_class($e), RestrictedDataProviderInterface::class), \E_USER_DEPRECATED);
  68.                 continue;
  69.             }
  70.         }
  71.         return $result;
  72.     }
  73. }