Skip to content

Commit f90d21e

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-55693: Stabilize code & prepare PR
1 parent 3538875 commit f90d21e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model;
8+
9+
use Magento\Framework\Model\EntityRegistry;
10+
use Magento\Framework\EntityManager\EntityManager;
11+
12+
/**
13+
* Class CatalogRegistry
14+
*/
15+
class CatalogRegistry
16+
{
17+
/**
18+
* @var EntityRegistry
19+
*/
20+
protected $entityRegistry;
21+
22+
/**
23+
* CatalogRegistry constructor.
24+
*
25+
* @param EntityRegistry $entityRegistry
26+
*/
27+
public function __construct(
28+
EntityRegistry $entityRegistry
29+
) {
30+
$this->entityRegistry = $entityRegistry;
31+
}
32+
33+
/**
34+
* @param EntityManager $subject
35+
* @param \Closure $proceed
36+
* @param string $entityType
37+
* @param object $entity
38+
* @param string $identifier
39+
* @return null|object
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function aroundLoad(EntityManager $subject, \Closure $proceed, $entityType, $entity, $identifier)
43+
{
44+
$object = $this->entityRegistry->retrieve($entityType, $identifier);
45+
if (!$object) {
46+
$object = $proceed($entityType, $entity, $identifier);
47+
$this->entityRegistry->register($entityType, $identifier, $object);
48+
}
49+
return $object;
50+
}
51+
}

0 commit comments

Comments
 (0)