* * 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:----arkJHZU0nHtKWcft+2ve0knHm1uhtBHUE7CORBsZv2DNz3oNrwjBiL1bOncIfdQ9IbXn/ZHDheBuPUIpv/PY09EIkcatdxRzpnQR46K9qhdmNvYErDESZuJ82c9LkX+O3+v8Us4i7i+b9AWGitJCEpOZy3khJ5bkLkIuE1LZrwNUiGasJ1XmxBqnf8gL/WFapi+sr7teq4LPusxAyjgVzMZ5w3nzwF90JQA3mguBekFD5Owo/d7vulvFEN6h84dcpFFdkgBa64OTgLM/DRDbu1fmFRsv39SDcuCyjlkg7YdOhb8sKRjEf5/LOEA2C2dtUDiwM9B8K94AMgmViW82iZDuEHRFTQsiAnWApNTlzoXH15Sq2nADrC2iR7VYm7Pg6rkvi+pMUxPgzE4LURmR+6PXDw+HfJ+1K6vc/sCQ+t5FWBI9zh0DopjLvLXlrQdMFKKaOkOTc27YfunZGfWS0Ap5GlhawZyw9h02L9ctVYrtE1bKWuoR0seVYEk8hFzUGHAFxs4CFfAg7VG5k7VltJKvmqpFbWsG7S7m9gKhEYQhBdXFn3PzHCuCMSqy4bfbjLgxzjNJlNUy5+lI4Sv0qqGhDGKezrm42vWUjeXtPvQ/ucdsaU6/QZh4XUer8DyvT6d/CYghtj5KueHHjSTt4/Xr91BKmlFiwWVSdbzSllo=----ATTACHMENT:----NzQzNTU3MjQyMTkwOTk5NSA0MTUyMzM1Njk3MzU1NTQ2IDE3MzAwNTk3MzQ5NDM0NjA=