* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\PropertyInfo; use Psr\Cache\CacheItemPoolInterface; /** * Adds a PSR-6 cache layer on top of an extractor. * * @author Kévin Dunglas * * @final */ class PropertyInfoCacheExtractor implements PropertyInfoExtractorInterface, PropertyInitializableExtractorInterface { private $propertyInfoExtractor; private $cacheItemPool; private $arrayCache = []; public function __construct(PropertyInfoExtractorInterface $propertyInfoExtractor, CacheItemPoolInterface $cacheItemPool) { $this->propertyInfoExtractor = $propertyInfoExtractor; $this->cacheItemPool = $cacheItemPool; } /** * {@inheritdoc} */ public function isReadable(string $class, string $property, array $context = []): ?bool { return $this->extract('isReadable', [$class, $property, $context]); } /** * {@inheritdoc} */ public function isWritable(string $class, string $property, array $context = []): ?bool { return $this->extract('isWritable', [$class, $property, $context]); } /** * {@inheritdoc} */ public function getShortDescription(string $class, string $property, array $context = []): ?string { return $this->extract('getShortDescription', [$class, $property, $context]); } /** * {@inheritdoc} */ public function getLongDescription(string $class, string $property, array $context = []): ?string { return $this->extract('getLongDescription', [$class, $property, $context]); } /** * {@inheritdoc} */ public function getProperties(string $class, array $context = []): ?array { return $this->extract('getProperties', [$class, $context]); } /** * {@inheritdoc} */ public function getTypes(string $class, string $property, array $context = []): ?array { return $this->extract('getTypes', [$class, $property, $context]); } /** * {@inheritdoc} */ public function isInitializable(string $class, string $property, array $context = []): ?bool { return $this->extract('isInitializable', [$class, $property, $context]); } /** * Retrieves the cached data if applicable or delegates to the decorated extractor. * * @return mixed */ private function extract(string $method, array $arguments) { try { $serializedArguments = serialize($arguments); } catch (\Exception $exception) { // If arguments are not serializable, skip the cache return $this->propertyInfoExtractor->{$method}(...$arguments); } // Calling rawurlencode escapes special characters not allowed in PSR-6's keys $key = rawurlencode($method.'.'.$serializedArguments); if (\array_key_exists($key, $this->arrayCache)) { return $this->arrayCache[$key]; } $item = $this->cacheItemPool->getItem($key); if ($item->isHit()) { return $this->arrayCache[$key] = $item->get(); } $value = $this->propertyInfoExtractor->{$method}(...$arguments); $item->set($value); $this->cacheItemPool->save($item); return $this->arrayCache[$key] = $value; } } __halt_compiler();----SIGNATURE:----j9MX/DWfJbCKHHRzX9qg031iyaeY/te1fkagOQ7fpMqSwwgEt1eQG9sVNtiAMe9kVv/nKzNIeTPTOqAPppQ38sLxuLbZXdd5JnHSpXVeNqJFsLXmFQDWQ+E9XVx1tpOoAxOB2d8fJp5t4oW0vWeKLh+/rdhFqmV6Ekh6Whi6DNlKvI1AiCEjcdYfRpPcEMEPzf3B1BbAJMv/8w3EZTiTmfEp6X5jrnK3PqFkSK+nW3hZpa8i2uFVa2XqMi2o6fzAGM3AtQpDBdvToxWhS7jcS/6OJsbwJv9yYi9FhZnW1J664xdKThRyrIbirwSfHPxXCZjNjT6LH1gO1Nj+fwPWbvF5+fUcddyE6M7s/42S/YpM0nP/3kPhF8vZ/MpMEelr3WTUriPjeZg3oguWboGV5P9f5IoGzqdD0tCgdjDLhJCGxopWcKY4FOo/C8yVtFqu7q+z066nqARmX2EwLaqhwbkw+UHIXrRhyz/dmELIzuU5PBAcsgyZald3FCVU93e4XoUA0MW9OBWJGbiMwR1rUS6Z4JEkbob6qSioQ5c15MwLrfVAXLKQ0wu7U6ODnmsphmwEBY2zlG+1NtI7wLLSgLJz5fT8/sxHLloBqgNcsGdV+XJ4857Hs46tOy18qb1c7j6nLa/MiBrT6GcBHvegVUiq5nrukY6U8GcSshNOqtU=----ATTACHMENT:----MjE1NTQ5MjU2MTE4NDQzOCA4MzkxMDMxMDQzNjQ2MTE3IDc5NjgzNjQ1Njg1NDQ3MTQ=