本文整理匯總了PHP中Zend\ModuleManager\ModuleManager::loadModules方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModuleManager::loadModules方法的具體用法?PHP ModuleManager::loadModules怎麽用?PHP ModuleManager::loadModules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\ModuleManager\ModuleManager
的用法示例。
在下文中一共展示了ModuleManager::loadModules方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processCommandTask
/**
* Process the command
*
* @return integer
*/
public function processCommandTask()
{
$modulePaths = $this->getModulePathsForProject();
// define module list
if ($this->params->paramModuleList && count($this->params->paramModuleList) > 0) {
// use modules parameter
$moduleList = $this->params->paramModuleList;
} else {
$moduleList = $this->loadModulesForProject($modulePaths);
}
// init loadable modules
$loadableModules = [];
// loop through module list
foreach ($moduleList as $moduleName) {
foreach ($modulePaths as $modulePath) {
// check module file
$moduleFile = $modulePath . '/' . $moduleName . '/Module.php';
if (file_exists($moduleFile)) {
$loadableModules[] = $moduleName;
}
}
}
// sort by key
sort($loadableModules);
// configure event managers
$sharedEvents = new SharedEventManager();
$eventManager = new EventManager($sharedEvents);
// configure module manager
$moduleManager = new ModuleManager($loadableModules, $eventManager);
// configure defaukt listeners
$defaultListeners = new DefaultListenerAggregate(new ListenerOptions(['module_paths' => $modulePaths]));
$defaultListeners->attach($moduleManager->getEventManager());
// load modules
$moduleManager->loadModules();
// set loaded modules
$this->params->loadedModules = $moduleManager->getLoadedModules();
// check loaded modules
if (!empty($this->params->loadedModules)) {
return 0;
}
// output fail message
$this->console->writeTaskLine('task_fetch_load_modules_not_found', [$this->console->colorize($this->params->workingPath, Color::GREEN)]);
return 1;
}
示例2: processCommandTask
/**
* Process the command
*
* @return integer
*/
public function processCommandTask()
{
// define module list
if ($this->params->paramModuleList && count($this->params->paramModuleList) > 0) {
// use modules parameter
$moduleList = $this->params->paramModuleList;
} else {
// fetch modules form path
$moduleList = scandir($this->params->projectModuleDir);
// clear unwanted entries
unset($moduleList[array_search('.', $moduleList)]);
unset($moduleList[array_search('..', $moduleList)]);
}
// check if Module.php file exists
foreach ($moduleList as $moduleKey => $moduleName) {
// check module file
$moduleFile = $this->params->projectModuleDir . '/' . $moduleName . '/Module.php';
if (!file_exists($moduleFile)) {
unset($moduleList[$moduleKey]);
}
}
// sort by key
sort($moduleList);
// configure event listeners for module manager
$sharedEvents = new SharedEventManager();
$defaultListeners = new DefaultListenerAggregate(new ListenerOptions(array('module_paths' => array($this->params->projectModuleDir))));
// configure module manager
$moduleManager = new ModuleManager($moduleList);
$moduleManager->getEventManager()->setSharedManager($sharedEvents);
$moduleManager->getEventManager()->attachAggregate($defaultListeners);
$moduleManager->loadModules();
// set loaded modules
$this->params->loadedModules = $moduleManager->getLoadedModules();
// check loaded modules
if (!empty($this->params->loadedModules)) {
return 0;
}
// output fail message
$this->console->writeTaskLine('task_fetch_load_modules_not_found', array($this->console->colorize($this->params->projectPath, Color::GREEN)));
return 1;
}
示例3: testModuleIsMarkedAsLoadedWhenLoadModuleEventIsTriggered
public function testModuleIsMarkedAsLoadedWhenLoadModuleEventIsTriggered()
{
$test = new stdClass();
$moduleManager = new ModuleManager(array('BarModule'));
$events = $moduleManager->getEventManager();
$events->attachAggregate($this->defaultListeners);
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, function ($e) use($test) {
$test->modules = $e->getTarget()->getLoadedModules(false);
});
$moduleManager->loadModules();
$this->assertTrue(isset($test->modules));
$this->assertArrayHasKey('BarModule', $test->modules);
$this->assertInstanceOf('BarModule\\Module', $test->modules['BarModule']);
}
示例4: testNotFoundModuleThrowsRuntimeException
public function testNotFoundModuleThrowsRuntimeException()
{
$this->setExpectedException('RuntimeException');
$moduleManager = new ModuleManager(array('NotFoundModule'));
$moduleManager->loadModules();
}
示例5: loadModules
/**
* Load the provided modules.
*
* @triggers loadModules.pre
* @triggers loadModules.post
* @return Manager
*/
public function loadModules()
{
$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULES_AUTH, $this, $this->getEvent());
return parent::loadModules();
}
示例6: testCanNotLoadSomeObjectModuleWithoutIdentifier
public function testCanNotLoadSomeObjectModuleWithoutIdentifier()
{
require_once __DIR__ . '/TestAsset/SomeModule/Module.php';
$configListener = $this->defaultListeners->getConfigListener();
$moduleManager = new ModuleManager(array(new \SomeModule\Module()), new EventManager());
$moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
$this->setExpectedException('Zend\\ModuleManager\\Exception\\RuntimeException');
$moduleManager->loadModules();
}
示例7: testCanLoadModuleDuringTheLoadModuleEvent
public function testCanLoadModuleDuringTheLoadModuleEvent()
{
$configListener = $this->defaultListeners->getConfigListener();
$moduleManager = new ModuleManager(array('LoadOtherModule', 'BarModule'));
$moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
$moduleManager->loadModules();
$config = $configListener->getMergedConfig();
$this->assertTrue(isset($config['loaded']));
$this->assertSame('oh, yeah baby!', $config['loaded']);
}
示例8: LoadModules
require_once 'library/Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->registerNamespace('SON', 'library/SON');
$loader->register();
/*
Evento:
- LoadModules (lista e pega todos os modulos da aplicação) foreach
* Zend\Loader\ModuleAutoloader
*
- LoadModule
- loadmodule.resolve (new Module();) instancia o objeto do modulo
- loadmodule
- getAutoloaderConfig() - possibilita ter seu proprio autoloader
- getConfig() - merge em relacao ao seu framework
- init(ModuleManager) - leve, somente o necessario
- onBootstrap - Zend\Mvc () - bootstrap event
- LocatorRegistrationListener implementar interface Zend\ModuleManager\Feature\LocatorRegisterdInterface
- ServiceListener (somente zend\mvc) services, controllers, plugins, view_helpers
- loadModules.post - todos os modulos ja foram carregados, agora eu posso atachar meus listener
*/
use Zend\ModuleManager\Listener;
use Zend\ModuleManager\ModuleManager;
$listenerOptions = new Listener\ListenerOptions(array('module_paths' => array('./modules')));
$aggregateListener = new Listener\DefaultListenerAggregate($listenerOptions);
$moduleManager = new ModuleManager(array('Modulo'));
$moduleManager->getEventManager()->attachAggregate($aggregateListener);
$moduleManager->loadModules();
示例9: createService
/**
* 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;
}