src/V4/Dev/APIPlatform/TraceableContextAwareCollectionDataProvider.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\V4\Dev\APIPlatform;
  3. use ApiPlatform\Core\Bridge\Symfony\Bundle\DataProvider\TraceableChainCollectionDataProvider as ApiPlatformTraceableChainCollectionDataProvider;
  4. use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
  5. use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
  6. use ReflectionClass;
  7. use Symfony\Component\Stopwatch\Stopwatch;
  8. class TraceableContextAwareCollectionDataProvider implements ContextAwareCollectionDataProviderInterface
  9. {
  10.     /**
  11.      * @var ApiPlatformTraceableChainCollectionDataProvider
  12.      */
  13.     private $decorated;
  14.     /**
  15.      * @var Stopwatch
  16.      */
  17.     private $stopwatch;
  18.     /**
  19.      * @param ApiPlatformTraceableChainCollectionDataProvider $decorated
  20.      * @param Stopwatch                                       $stopwatch
  21.      */
  22.     public function __construct(
  23.         ApiPlatformTraceableChainCollectionDataProvider $decorated,
  24.         Stopwatch $stopwatch
  25.     ) {
  26.         $this->decorated $decorated;
  27.         $this->stopwatch $stopwatch;
  28.     }
  29.     /**
  30.      * @param string      $resourceClass
  31.      * @param string|null $operationName
  32.      * @param array       $context
  33.      *
  34.      * @return array|iterable
  35.      *
  36.      * @throws ResourceClassNotSupportedException
  37.      */
  38.     public function getCollection(string $resourceClassstring $operationName null, array $context = [])
  39.     {
  40.         $stopwatchKey sprintf('%s->%s_%s', (new ReflectionClass($this->decorated))->getShortName(), $resourceClass$operationName);
  41.         $this->stopwatch->start($stopwatchKey'ContextAwareCollectionDataProvider');
  42.         $results $this->decorated->getCollection($resourceClass$operationName$context);
  43.         $this->stopwatch->stop($stopwatchKey);
  44.         return $results;
  45.     }
  46. }