src/V4/Dev/APIPlatform/TraceableItemDataProvider.php line 45

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