vendor/api-platform/core/src/Core/Bridge/Symfony/Routing/CachedRouteNameResolver.php line 43

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\Routing;
  12. use ApiPlatform\Util\CachedTrait;
  13. use Psr\Cache\CacheItemPoolInterface;
  14. /**
  15.  * @author Teoh Han Hui <teohhanhui@gmail.com>
  16.  */
  17. final class CachedRouteNameResolver implements RouteNameResolverInterface
  18. {
  19.     use CachedTrait;
  20.     public const CACHE_KEY_PREFIX 'route_name_';
  21.     private $decorated;
  22.     public function __construct(CacheItemPoolInterface $cacheItemPoolRouteNameResolverInterface $decorated)
  23.     {
  24.         $this->cacheItemPool $cacheItemPool;
  25.         $this->decorated $decorated;
  26.     }
  27.     public function getRouteName(string $resourceClass$operationType /* , array $context = [] */): string
  28.     {
  29.         $context = \func_num_args() > func_get_arg(2) : [];
  30.         $cacheKey self::CACHE_KEY_PREFIX.md5(serialize([$resourceClass$operationType$context['subresource_resources'] ?? null]));
  31.         return $this->getCached($cacheKey, function () use ($resourceClass$operationType$context) {
  32.             return $this->decorated->getRouteName($resourceClass$operationType$context);
  33.         });
  34.     }
  35. }