-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
ObjectManager.php
63 lines (58 loc) · 1.73 KB
/
ObjectManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
*/
namespace Magento\Framework\App;
use Magento\Framework\ObjectManager\FactoryInterface;
/**
* A wrapper around object manager with workarounds to access it in client code
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ObjectManager extends \Magento\Framework\ObjectManager\ObjectManager
{
/**
* @var ObjectManager
*/
protected static $_instance;
/**
* Retrieve object manager
*
* TODO: Temporary solution for serialization, should be removed when Serialization problem is resolved
*
* @deprecated
* @return ObjectManager
* @throws \RuntimeException
*/
public static function getInstance()
{
if (!self::$_instance instanceof \Magento\Framework\ObjectManagerInterface) {
throw new \RuntimeException('ObjectManager isn\'t initialized');
}
return self::$_instance;
}
/**
* Set object manager instance
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @throws \LogicException
* @return void
*/
public static function setInstance(\Magento\Framework\ObjectManagerInterface $objectManager)
{
self::$_instance = $objectManager;
}
/**
* @param FactoryInterface $factory
* @param \Magento\Framework\ObjectManager\ConfigInterface $config
* @param array $sharedInstances
*/
public function __construct(
FactoryInterface $factory,
\Magento\Framework\ObjectManager\ConfigInterface $config,
array $sharedInstances = []
) {
parent::__construct($factory, $config, $sharedInstances);
self::$_instance = $this;
}
}