AppserverIo\Appserver\Application\Application::addManager PHP Method

addManager() public method

Injects manager instance and the configuration.
public addManager ( AppserverIo\Psr\Application\ManagerInterface $manager, AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $configuration ) : void
$manager AppserverIo\Psr\Application\ManagerInterface A manager instance
$configuration AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface The managers configuration
return void
    public function addManager(ManagerInterface $manager, ManagerNodeInterface $configuration)
    {
        // bind the manager callback to the naming directory => the application itself
        $this->getNamingDirectory()->bind(sprintf('php:global/%s/%s', $this->getUniqueName(), $configuration->getName()), array(&$this, 'getManager'), array($configuration->getName()));
        // add the manager instance to the application
        $this->managers[$configuration->getName()] = $manager;
    }

Usage Example

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());
 }