本文整理匯總了PHP中Zend\ModuleManager\ModuleManager::getLoadedModules方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModuleManager::getLoadedModules方法的具體用法?PHP ModuleManager::getLoadedModules怎麽用?PHP ModuleManager::getLoadedModules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\ModuleManager\ModuleManager
的用法示例。
在下文中一共展示了ModuleManager::getLoadedModules方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLoadedModules
private function getLoadedModules()
{
if (null === $this->loadedModules) {
$this->loadedModules = $this->moduleManager->getLoadedModules();
}
return $this->loadedModules;
}
示例2: showAction
public function showAction()
{
$this->composerInfo->parse();
$loadedModules = $this->moduleManager->getLoadedModules();
$packages = $this->composerInfo->getPackages();
$this->viewModel->setPackages($packages);
$this->viewModel->setLoadedModules($loadedModules);
$this->viewModel->setTemplate('list-show');
return $this->renderer->render($this->viewModel);
}
示例3: 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;
}
示例4: 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;
}
示例5: getEnabledModules
/**
* Returns list of all API-First-enabled modules
*
* @return array
*/
protected function getEnabledModules()
{
if (is_array($this->modules)) {
return $this->modules;
}
$this->modules = array();
foreach ($this->moduleManager->getLoadedModules() as $moduleName => $module) {
if (!$module instanceof ApigilityProviderInterface && !$module instanceof ApigilityModuleInterface) {
continue;
}
if ($module instanceof ApigilityModuleInterface) {
trigger_error('ZF\\Apigility\\ApigilityModuleInterface is deprecated,
use ZF\\Apigility\\Provider\\ApigilityProviderInterface instead', E_USER_DEPRECATED);
}
$services = $this->getServicesByModule($moduleName);
$versions = $this->getVersionsByModule($moduleName, $module);
$entity = new ModuleEntity($moduleName, $services['rest'], $services['rpc']);
$entity->exchangeArray(array('versions' => $versions, 'default_version' => $this->getModuleDefaultVersion($module)));
$this->modules[$entity->getName()] = $entity;
}
return $this->modules;
}
示例6: testModuleLoadingBehavior
public function testModuleLoadingBehavior()
{
$moduleManager = new ModuleManager(array('BarModule'));
$moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
$modules = $moduleManager->getLoadedModules();
$this->assertSame(0, count($modules));
$modules = $moduleManager->getLoadedModules(true);
$this->assertSame(1, count($modules));
$moduleManager->loadModules();
// should not cause any problems
$moduleManager->loadModule('BarModule');
// should not cause any problems
$modules = $moduleManager->getLoadedModules(true);
// BarModule already loaded so nothing happens
$this->assertSame(1, count($modules));
}
示例7: testCanLoadMultipleModulesObjectWithString
public function testCanLoadMultipleModulesObjectWithString()
{
require_once __DIR__ . '/TestAsset/SomeModule/Module.php';
$configListener = $this->defaultListeners->getConfigListener();
$moduleManager = new ModuleManager(array('SomeModule' => new \SomeModule\Module(), 'BarModule'), new EventManager());
$moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
$moduleManager->loadModules();
$loadedModules = $moduleManager->getLoadedModules();
$this->assertInstanceOf('SomeModule\\Module', $loadedModules['SomeModule']);
$config = $configListener->getMergedConfig();
$this->assertSame($config->some, 'thing');
}
示例8: __construct
/**
* @param ModuleManager $modules
*/
public function __construct(ModuleManager $modules)
{
$this->modules = $modules->getLoadedModules();
}
示例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;
}
示例10: runAction
/**
* Run diagnostics
*
* @return ConsoleModel|ViewModel
* @throws \ZFTool\Diagnostics\Exception\RuntimeException
*/
public function runAction()
{
// check for help mode
if ($this->requestOptions->getFlagHelp()) {
return $this->runHelp();
}
// get needed options to shorten code
$flagVerbose = $this->requestOptions->getFlagVerbose();
$flagDebug = $this->requestOptions->getFlagDebug();
$flagQuiet = $this->requestOptions->getFlagQuiet();
$flagBreak = $this->requestOptions->getFlagBreak();
$testGroupName = $this->requestOptions->getTestGroupName();
// output header
if (!$flagQuiet) {
$this->consoleHeader('Starting diagnostics for Zend Framework 2 project');
}
// start output
if (!$flagQuiet) {
$this->console->writeLine(' => Get basic diag configuration');
}
// Get basic diag configuration
$config = isset($this->configuration['diagnostics']) ? $this->configuration['diagnostics'] : array();
// start output
if (!$flagQuiet) {
$this->console->writeLine(' => Collect diag tests from modules ');
}
// Collect diag tests from modules
$modules = $this->moduleManager->getLoadedModules(false);
foreach ($modules as $moduleName => $module) {
if (is_callable(array($module, 'getDiagnostics'))) {
$tests = $module->getDiagnostics();
if (is_array($tests)) {
$config[$moduleName] = $tests;
}
// Exit the loop early if we found test definitions for
// the only test group that we want to run.
if ($testGroupName && $moduleName == $testGroupName) {
break;
}
}
}
// Filter array if a test group name has been provided
if ($testGroupName) {
$config = array_intersect_key($config, array($testGroupName => 1));
}
// start output
if (!$flagQuiet) {
$this->console->writeLine(' => Analyze test definitions and construct test instances');
}
// Analyze test definitions and construct test instances
$testCollection = array();
foreach ($config as $testGroupName => $tests) {
foreach ($tests as $testLabel => $test) {
// Do not use numeric labels.
if (!$testLabel || is_numeric($testLabel)) {
$testLabel = false;
}
// Handle a callable.
if (is_callable($test)) {
$test = new Callback($test);
if ($testLabel) {
$test->setLabel($testGroupName . ': ' . $testLabel);
}
$testCollection[] = $test;
continue;
}
// Handle test object instance.
if (is_object($test)) {
if (!$test instanceof TestInterface) {
throw new RuntimeException('Cannot use object of class "' . get_class($test) . '" as test. ' . 'Expected instance of ZFTool\\Diagnostics\\Test\\TestInterface');
}
if ($testLabel) {
$test->setLabel($testGroupName . ': ' . $testLabel);
}
$testCollection[] = $test;
continue;
}
// Handle an array containing callback or identifier with optional parameters.
if (is_array($test)) {
if (!count($test)) {
throw new RuntimeException('Cannot use an empty array() as test definition in "' . $testGroupName . '"');
}
// extract test identifier and store the remainder of array as parameters
$testName = array_shift($test);
$params = $test;
} elseif (is_scalar($test)) {
$testName = $test;
$params = array();
} else {
throw new RuntimeException('Cannot understand diagnostic test definition "' . gettype($test) . '" in "' . $testGroupName . '"');
}
// Try to expand test identifier using Service Locator
if (is_string($testName) && $this->getServiceLocator()->has($testName)) {
$test = $this->getServiceLocator()->get($testName);
//.........這裏部分代碼省略.........