![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-eav/Plugin/Model/ResourceModel/Entity/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Eav\Plugin\Model\ResourceModel\Entity; use Magento\Eav\Model\Cache\Type; use Magento\Eav\Model\Entity\Attribute as EntityAttribute; use Magento\Eav\Model\ResourceModel\Entity\Attribute as AttributeResource; use Magento\Framework\App\Cache\StateInterface; use Magento\Framework\App\CacheInterface; use Magento\Framework\Serialize\SerializerInterface; class Attribute { /** * Cache key for store label attribute */ const STORE_LABEL_ATTRIBUTE = 'EAV_STORE_LABEL_ATTRIBUTE'; /** * @var CacheInterface */ private $cache; /** * @var StateInterface */ private $cacheState; /** * @var SerializerInterface */ private $serializer; /** * @param CacheInterface $cache * @param StateInterface $cacheState * @param SerializerInterface $serializer * @codeCoverageIgnore */ public function __construct( CacheInterface $cache, StateInterface $cacheState, SerializerInterface $serializer ) { $this->cache = $cache; $this->serializer = $serializer; $this->cacheState = $cacheState; } /** * @param AttributeResource $subject * @param callable $proceed * @param int $attributeId * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetStoreLabelsByAttributeId( AttributeResource $subject, \Closure $proceed, $attributeId ) { $cacheId = self::STORE_LABEL_ATTRIBUTE . $attributeId; if ($this->isCacheEnabled() && ($storeLabels = $this->cache->load($cacheId))) { return $this->serializer->unserialize($storeLabels); } $storeLabels = $proceed($attributeId); if ($this->isCacheEnabled()) { $this->cache->save( $this->serializer->serialize($storeLabels), $cacheId, [ Type::CACHE_TAG, EntityAttribute::CACHE_TAG ] ); } return $storeLabels; } /** * Check if cache is enabled * * @return bool */ private function isCacheEnabled() { return $this->cacheState->isEnabled(Type::TYPE_IDENTIFIER); } }