src/V4/Dev/Transformer/TraceableListingResponseTransformer.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\V4\Dev\Transformer;
  3. use App\Listing\Transformer\ListingResponseTransformerInterface;
  4. use ReflectionClass;
  5. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  6. use Symfony\Component\Stopwatch\Stopwatch;
  7. class TraceableListingResponseTransformer implements ListingResponseTransformerInterface
  8. {
  9.     /**
  10.      * @var ListingResponseTransformerInterface
  11.      */
  12.     private $decorated;
  13.     /**
  14.      * @var Stopwatch
  15.      */
  16.     private $stopwatch;
  17.     /**
  18.      * @param ListingResponseTransformerInterface $decorated
  19.      * @param Stopwatch                           $stopwatch
  20.      */
  21.     public function __construct(
  22.         ListingResponseTransformerInterface $decorated,
  23.         Stopwatch $stopwatch
  24.     ) {
  25.         $this->decorated $decorated;
  26.         $this->stopwatch $stopwatch;
  27.     }
  28.     /**
  29.      * @param string $entityFQCN
  30.      * @param array  $entities
  31.      * @param array  $context
  32.      *
  33.      * @return array
  34.      *
  35.      * @throws ExceptionInterface
  36.      */
  37.     public function transform(string $entityFQCN, array $entities, array $context = []): array
  38.     {
  39.         $stopwatchKey sprintf('%s->%s', (new ReflectionClass($this->decorated))->getShortName(), $entityFQCN);
  40.         $this->stopwatch->start($stopwatchKey'ListingResponseTransformer');
  41.         $results $this->decorated->transform($entityFQCN$entities$context);
  42.         $this->stopwatch->stop($stopwatchKey);
  43.         return $results;
  44.     }
  45. }