/** * Configures a module in context of the given application. * * @param AbstractModule $module Module to be configured. * @param AbstractApplication $application Application for which this module should be configured. * @param string $env [optional] Environment in which the application is running. Default: `dev`. * @param boolean $debug [optional] Debug mode status for the application. Default: `true`. */ public function configureModule(AbstractModule $module, AbstractApplication $application, $env = 'dev', $debug = true) { $container = $application->getContainer(); $config = $application->getConfig(); // define config for the module $container->register('config.' . $module->getName(), array('extends' => 'config_module.abstract')); // add method calls to load appropriate config files to the definition $configDefinition = $container->getDefinition('config.' . $module->getName()); $configDir = rtrim($module->getConfigDir(), DS); $configFiles = array_merge(FilesystemUtils::glob($configDir . '/config.{yml,yaml,php}', GLOB_BRACE), FilesystemUtils::glob($configDir . '/config.' . $env . '.{yml,yaml,php}', GLOB_BRACE)); foreach ($configFiles as $file) { $configDefinition->addMethodCall('loadFromFile', array($file)); } // add method call to apply the config from the application config $configDefinition->addMethodCall('apply', array($config->getNamespace($module->getName()))); // let it configure itself $module->configure(); }