AppserverIo\Appserver\Application\Application::initializeManagers PHP Метод

initializeManagers() публичный Метод

Registers all managers in the application.
public initializeManagers ( ) : void
Результат void
    public function initializeManagers()
    {
        // initialize the registered managers
        /** @var \AppserverIo\Psr\Application\ManagerInterface $manager */
        foreach ($this->getManagers() as $manager) {
            // log the manager we want to initialize
            $this->getInitialContext()->getSystemLogger()->info(sprintf('Now register manager %s for application %s', get_class($manager), $this->getName()));
            // initialize the manager instance
            $manager->initialize($this);
            // log the manager we've successfully registered
            $this->getInitialContext()->getSystemLogger()->info(sprintf('Now registered manager %s for application %s', get_class($manager), $this->getName()));
        }
    }

Usage Example

Пример #1
0
 /**
  * Test if the managers has been initialized successfully.
  *
  * @return void
  */
 public function testInitializeManagers()
 {
     // initialize the mock logger
     $mockLogger = $this->getMock('Psr\\Log\\LoggerInterface', array('log', 'error', 'warning', 'notice', 'emergency', 'debug', 'info', 'alert', 'critical'));
     // create a mock instance
     $classToMock = 'AppserverIo\\Appserver\\Application\\Interfaces\\ContextInterface';
     $mockInitialContext = $this->getMock($classToMock, get_class_methods($classToMock));
     $mockInitialContext->expects($this->any())->method('getSystemLogger')->will($this->returnValue($mockLogger));
     // inject the mock initial context instance
     $this->application->injectInitialContext($mockInitialContext);
     // create a mock manager configuration
     $classToMock = 'AppserverIo\\Appserver\\Core\\Api\\Node\\ManagerNodeInterface';
     $mockManagerConfiguration = $this->getMock($classToMock, get_class_methods($classToMock));
     $mockManagerConfiguration->expects($this->any())->method('getName')->will($this->returnValue('MockManager'));
     // register the mock manager instance
     $this->application->addManager($mockManager = new MockManager(), $mockManagerConfiguration);
     $this->application->initializeManagers();
     // check that the mock manager has been initialized
     $this->assertTrue($mockManager->isInitialized());
 }