Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ObjectManagerProvider Class Reference

Public Member Functions

 __construct (ServiceLocatorInterface $serviceLocator, Bootstrap $bootstrap)
 
 get ()
 
 reset ()
 
 setObjectManager (ObjectManagerInterface $objectManager)
 
 getObjectManagerFactory ($initParams=[])
 

Detailed Description

Object manager provider

Links Zend Framework's service locator and Magento object manager. Guaranties single object manager per application run. Hides complexity of creating Magento object manager

Definition at line 22 of file ObjectManagerProvider.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ServiceLocatorInterface  $serviceLocator,
Bootstrap  $bootstrap 
)
Parameters
ServiceLocatorInterface$serviceLocator
Bootstrap$bootstrap

Definition at line 43 of file ObjectManagerProvider.php.

46  {
47  $this->serviceLocator = $serviceLocator;
48  $this->bootstrap = $bootstrap;
49  }
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
Definition: bootstrap.php:73

Member Function Documentation

◆ get()

get ( )

Retrieve object manager.

Returns
ObjectManagerInterface
Exceptions

Definition at line 57 of file ObjectManagerProvider.php.

58  {
59  if (null === $this->objectManager) {
60  $initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM);
61  $factory = $this->getObjectManagerFactory($initParams);
62  $this->objectManager = $factory->create($initParams);
63  if (PHP_SAPI == 'cli') {
64  $this->createCliCommands();
65  }
66  }
67  return $this->objectManager;
68  }
$objectManager
Definition: bootstrap.php:17

◆ getObjectManagerFactory()

getObjectManagerFactory (   $initParams = [])

Returns ObjectManagerFactory

Parameters
array$initParams
Returns
\Magento\Framework\App\ObjectManagerFactory

Definition at line 113 of file ObjectManagerProvider.php.

114  {
115  return $this->bootstrap->createObjectManagerFactory(
116  BP,
117  $initParams
118  );
119  }
const BP
Definition: autoload.php:14

◆ reset()

reset ( )

Causes object manager to be reinitialized the next time it is retrieved.

Returns
void

Definition at line 91 of file ObjectManagerProvider.php.

92  {
93  $this->objectManager = null;
94  }

◆ setObjectManager()

setObjectManager ( ObjectManagerInterface  $objectManager)

Sets object manager

Parameters
ObjectManagerInterface$objectManager
Returns
void

Definition at line 102 of file ObjectManagerProvider.php.

103  {
104  $this->objectManager = $objectManager;
105  }
$objectManager
Definition: bootstrap.php:17

The documentation for this class was generated from the following file: