Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CachedMetadata.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
16  const CACHE_SEPARATOR = ';';
17 
21  protected $entityType = 'none';
22 
26  private $attributeMetadataCache;
27 
31  protected $metadata;
32 
39  public function __construct(
41  AttributeMetadataCache $attributeMetadataCache = null
42  ) {
43  $this->metadata = $metadata;
44  $this->attributeMetadataCache = $attributeMetadataCache ?: ObjectManager::getInstance()
45  ->get(AttributeMetadataCache::class);
46  }
47 
51  public function getAttributes($formCode)
52  {
53  $attributes = $this->attributeMetadataCache->load($this->entityType, $formCode);
54  if ($attributes !== false) {
55  return $attributes;
56  }
57  $attributes = $this->metadata->getAttributes($formCode);
58  $this->attributeMetadataCache->save($this->entityType, $attributes, $formCode);
59  return $attributes;
60  }
61 
66  {
67  $attributesMetadata = $this->attributeMetadataCache->load($this->entityType, $attributeCode);
68  if (false !== $attributesMetadata) {
69  return array_shift($attributesMetadata);
70  }
71  $attributeMetadata = $this->metadata->getAttributeMetadata($attributeCode);
72  $this->attributeMetadataCache->save($this->entityType, [$attributeMetadata], $attributeCode);
73  return $attributeMetadata;
74  }
75 
79  public function getAllAttributesMetadata()
80  {
81  $attributes = $this->attributeMetadataCache->load($this->entityType, 'all');
82  if ($attributes !== false) {
83  return $attributes;
84  }
85  $attributes = $this->metadata->getAllAttributesMetadata();
86  $this->attributeMetadataCache->save($this->entityType, $attributes, 'all');
87  return $attributes;
88  }
89 
93  public function getCustomAttributesMetadata($dataObjectClassName = null)
94  {
95  $attributes = $this->attributeMetadataCache->load($this->entityType, 'custom');
96  if ($attributes !== false) {
97  return $attributes;
98  }
99  $attributes = $this->metadata->getCustomAttributesMetadata();
100  $this->attributeMetadataCache->save($this->entityType, $attributes, 'custom');
101  return $attributes;
102  }
103 }
getCustomAttributesMetadata($dataObjectClassName=null)
$attributeCode
Definition: extend.phtml:12
$attributes
Definition: matrix.phtml:13
__construct(MetadataInterface $metadata, AttributeMetadataCache $attributeMetadataCache=null)