/** * Creates and returns the module manager * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfig * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator Service Manager * * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $moduleCollection = new ModuleCollection(); $modules = $moduleCollection->getModules(); $array = array(); $autoloader = AutoloaderFactory::getRegisteredAutoloader(AutoloaderFactory::STANDARD_AUTOLOADER); foreach ($modules as $module) { $array[] = $module->getName(); $path = GC_APPLICATION_PATH . '/library/Modules/' . $module->getName(); if (file_exists($path) === false) { $path = GC_APPLICATION_PATH . '/extensions/Modules/' . $module->getName(); } $autoloader->registerNamespace($module->getName(), $path); } $autoloader->register(); $application = $serviceLocator->get('Application'); $configuration = $serviceLocator->get('ApplicationConfig'); $configuration['module_listener_options']['module_paths'] = array('./library/Modules', './extensions/Modules'); $listenerOptions = new Listener\ListenerOptions($configuration['module_listener_options']); $defaultListeners = new Listener\DefaultListenerAggregate($listenerOptions); $serviceListener = new Listener\ServiceListener($serviceLocator); $this->prepareServices($serviceListener, $serviceLocator); $moduleManager = new ModuleManager($array, $application->getEventManager()); $moduleManager->getEventManager()->attachAggregate($defaultListeners); $moduleManager->getEventManager()->attachAggregate($serviceListener); $moduleManager->loadModules(); $config = $moduleManager->getEvent()->getConfigListener()->getMergedConfig(false); $this->prepareConfig($serviceLocator, $config); foreach ($moduleManager->getLoadedModules() as $module) { if (method_exists($module, 'onBootstrap')) { $module->onBootstrap($application->getMvcEvent()); } } return $moduleManager; }
/** * @throws \Exception */ protected static function autoload() { if (file_exists('vendor/autoload.php')) { $loader = (require 'vendor/autoload.php'); } // the entire application is based on Composer loader, but just in case // let's instantiate the loader if I can't find Composer's ClassLoader if (empty($loader)) { switch (true) { case file_exists('vendor/zendframework/zendframework/library/Zend/Loader/AutoloaderFactory.php'): require_once 'vendor/zendframework/zendframework/library/Zend/Loader/AutoloaderFactory.php'; \Zend\Loader\AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('autoregister_zf' => true, 'fallback_autoloader' => true))); require_once 'vendor/zendframework/zendframework/library/Zend/Loader/StandardAutoloader.php'; $loader = \Zend\Loader\AutoloaderFactory::getRegisteredAutoloader('Zend\\Loader\\StandardAutoloader'); break; // @TODO: case file_exists('path/to/Symfony/Loader.php') / Implement when you'll need it // @TODO: case file_exists('path/to/Symfony/Loader.php') / Implement when you'll need it default: throw new \Exception('Could not find neither Zend nor Composer or Symfony libraries for creating a class loader!'); } } // register Netis only. The real class loader will be instantiated inside the Application classes switch (true) { case $loader instanceof \Zend\Loader\SplAutoloader: $loader->registerPrefix('Netis', 'vendor/athemcms/Netis/library/Netis'); break; case $loader instanceof \Composer\Autoload\ClassLoader: $loader->add('Netis', 'vendor/athemcms/netis/library'); break; // @TODO: Implement Symfony when you'll need it as well :D // @TODO: Implement Symfony when you'll need it as well :D default: throw new \Exception('No Loader detected!'); } }
public static function initVuFind() { define('APPLICATION_ENV', 'development'); define('SWISSBIB_TEST_FIXTURES', realpath(__DIR__ . '/fixtures')); // Setup autoloader for VuFindTest classes $loader = \Zend\Loader\AutoloaderFactory::getRegisteredAutoloader(\Zend\Loader\AutoloaderFactory::STANDARD_AUTOLOADER); $loader->registerNamespace('VuFindTest', __DIR__ . '/../../VuFind/src/VuFindTest'); }
public function testGetInvalidAutoloaderThrowsException() { $this->setExpectedException('Zend\\Loader\\Exception\\InvalidArgumentException'); $loader = AutoloaderFactory::getRegisteredAutoloader('InvalidAutoloader'); }
/** * @see \Netis\Application\ApplicationInterface#registerLoader() * @param array $options * @return $this * @throws \Exception */ public function registerLoader($options = array()) { if (empty($options['type'])) { $option['type'] = 'composer'; } $zf2Path = isset($options['zf2path']) ? $options['zf2path'] : 'vendor/zendframework/zendframework/library'; switch ($options['type']) { case 'composer': self::$loader = (include 'vendor/autoload.php'); if (empty(self::$loader)) { throw new Exception\MissingClassLoaderException('Missing ClassLoader Composer!'); } break; case 'zend': // register zend autoloader (since the entire CMS is based on Zend) require_once $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; \Zend\Loader\AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('autoregister_zf' => true, 'fallback_autoloader' => true))); require_once $zf2Path . '/Zend/Loader/StandardAutoloader.php'; self::$loader = \Zend\Loader\AutoloaderFactory::getRegisteredAutoloader('Zend\\Loader\\StandardAutoloader'); break; case 'symfony': // @TODO: Implement Symfony ClassLoader when you need it! throw new Exception\MissingClassLoaderException('Symfony ClassLoader is not implemented yet.'); } // register needed namespaces $namespaces = array('Athem' => 'vendor/athem/athem/library', 'Netis' => 'vendor/athemcms/netis/library'); if (!empty($options['namespaces'])) { $namespaces = \Athem\Utils::arrayMergeRecursiveRight($namespaces, $options['namespaces']); } $this->registerNamespaces($namespaces); // register doctrine annotation namespaces // @TODO: Not correct! This way, application is depended 100% of Zend Lbrary. Should remove Zend\Form\Annotation, to be added in configs $annotationNamespaces = array("Doctrine\\ORM\\Mapping" => getcwd() . "/vendor/doctrine/orm/lib/", "Zend\\Form\\Annotation" => getcwd() . "/vendor/zendframework/zendframework/library"); if (!empty($options['annotationNamespaces'])) { $annotationNamespaces = \Athem\Utils::arrayMergeRecursiveRight($annotationNamespaces, $options['annotationNamespaces']); } $this->registerAnnotationNamespaces($annotationNamespaces); return $this; }