<?php
namespace App\V4\Dev\Transformer;
use App\Listing\Transformer\ListingResponseTransformerInterface;
use ReflectionClass;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Stopwatch\Stopwatch;
class TraceableListingResponseTransformer implements ListingResponseTransformerInterface
{
/**
* @var ListingResponseTransformerInterface
*/
private $decorated;
/**
* @var Stopwatch
*/
private $stopwatch;
/**
* @param ListingResponseTransformerInterface $decorated
* @param Stopwatch $stopwatch
*/
public function __construct(
ListingResponseTransformerInterface $decorated,
Stopwatch $stopwatch
) {
$this->decorated = $decorated;
$this->stopwatch = $stopwatch;
}
/**
* @param string $entityFQCN
* @param array $entities
* @param array $context
*
* @return array
*
* @throws ExceptionInterface
*/
public function transform(string $entityFQCN, array $entities, array $context = []): array
{
$stopwatchKey = sprintf('%s->%s', (new ReflectionClass($this->decorated))->getShortName(), $entityFQCN);
$this->stopwatch->start($stopwatchKey, 'ListingResponseTransformer');
$results = $this->decorated->transform($entityFQCN, $entities, $context);
$this->stopwatch->stop($stopwatchKey);
return $results;
}
}