Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObjectManager.php
Go to the documentation of this file.
1 <?php
14 
16 {
20  protected $_factory;
21 
27  protected $_sharedInstances = [];
28 
32  protected $_config;
33 
39  public function __construct(FactoryInterface $factory, ConfigInterface $config, &$sharedInstances = [])
40  {
41  $this->_config = $config;
42  $this->_factory = $factory;
43  $this->_sharedInstances = &$sharedInstances;
44  $this->_sharedInstances[\Magento\Framework\ObjectManagerInterface::class] = $this;
45  }
46 
54  public function create($type, array $arguments = [])
55  {
56  return $this->_factory->create($this->_config->getPreference($type), $arguments);
57  }
58 
65  public function get($type)
66  {
67  $type = ltrim($type, '\\');
68  $type = $this->_config->getPreference($type);
69  if (!isset($this->_sharedInstances[$type])) {
70  $this->_sharedInstances[$type] = $this->_factory->create($type);
71  }
72  return $this->_sharedInstances[$type];
73  }
74 
82  public function configure(array $configuration)
83  {
84  $this->_config->extend($configuration);
85  }
86 }
$configuration
Definition: index.php:33
$config
Definition: fraud_order.php:17
__construct(FactoryInterface $factory, ConfigInterface $config, &$sharedInstances=[])
$type
Definition: item.phtml:13
$arguments