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
6 namespace Magento\Framework\App;
7 
9 
21 {
25  protected static $_instance;
26 
33  public static function getInstance()
34  {
35  if (!self::$_instance instanceof \Magento\Framework\ObjectManagerInterface) {
36  throw new \RuntimeException('ObjectManager isn\'t initialized');
37  }
38  return self::$_instance;
39  }
40 
48  public static function setInstance(\Magento\Framework\ObjectManagerInterface $objectManager)
49  {
50  self::$_instance = $objectManager;
51  }
52 
58  public function __construct(
61  array &$sharedInstances = []
62  ) {
63  parent::__construct($factory, $config, $sharedInstances);
64  self::$_instance = $this;
65  }
66 }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17
static setInstance(\Magento\Framework\ObjectManagerInterface $objectManager)
__construct(FactoryInterface $factory, \Magento\Framework\ObjectManager\ConfigInterface $config, array &$sharedInstances=[])