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

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

Registers all class loaders injected to the applications in the opposite order as they have been injected.
public registerClassLoaders ( ) : void
Результат void
    public function registerClassLoaders()
    {
        // initialize the registered managers
        /** @var \AppserverIo\Appserver\Core\Interfaces\ClassLoaderInterface $classLoader */
        foreach ($this->getClassLoaders() as $classLoader) {
            // log the class loader we want to initialize
            $this->getInitialContext()->getSystemLogger()->debug(sprintf('Now register classloader %s for application %s', get_class($classLoader), $this->getName()));
            // register the class loader instance
            $classLoader->register(true, true);
            // log the class loader we've successfully registered
            $this->getInitialContext()->getSystemLogger()->debug(sprintf('Successfully registered classloader %s for application %s', get_class($classLoader), $this->getName()));
        }
    }

Usage Example

Пример #1
0
 /**
  * Test if the class loaders has been registered successfully.
  *
  * @return void
  */
 public function testRegisterClassLoaders()
 {
     // 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 loader configuration
     $classToMock = 'AppserverIo\\Appserver\\Core\\Api\\Node\\ClassLoaderNodeInterface';
     $mockLoaderConfiguration = $this->getMock($classToMock, get_class_methods($classToMock));
     $mockLoaderConfiguration->expects($this->any())->method('getName')->will($this->returnValue('MockLoader'));
     // register the mock class loader instance
     $this->application->addClassLoader($mockClassLoader = new MockClassLoader(), $mockLoaderConfiguration);
     $this->application->registerClassLoaders();
     // check that the mock class loader has been registered
     $this->assertTrue($mockClassLoader->isRegistered());
 }