Skip to content

Instantly share code, notes, and snippets.

@DracoBlue
Created March 30, 2010 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DracoBlue/349541 to your computer and use it in GitHub Desktop.
Save DracoBlue/349541 to your computer and use it in GitHub Desktop.
<?php
protected $module_folders = null;
/**
* Extended initializeModule for Agavi, allowing multiple modules-folders. *
*/
public function initializeModule($moduleName)
{
$lowerModuleName = strtolower($moduleName);
$module_path = AgaviConfig::get('core.module_dir');
$module_variable = '%core.module_dir%';
if (null === AgaviConfig::get('modules.' . $lowerModuleName . '.path')) {
/*
* If there is no path for the module present, let's search for it
*/
if(null !== AgaviConfig::get('modules.folders')) {
/*
* Perfect, we set a modules.folders property! Let's find those.
*/
if ($this->module_folders === null) {
/*
* We haven't initialized the $this->module_folders member, yet
*/
$this->module_folders = array();
$module_folder_names = explode(',', AgaviConfig::get('modules.folders'));
foreach ($module_folder_names as $folder_name) {
$this->module_folders[] = array(
'path' => $folder_name,
'variable' => $folder_name
);
}
}
foreach ($this->module_folders as $module_folder) {
if (is_dir($module_folder['path'] . DIRECTORY_SEPARATOR . $moduleName)) {
$module_path = $module_folder['path'];
$module_variable = $module_folder['variable'];
break;
}
}
}
}
if(null === AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
// set some defaults first
AgaviConfig::fromArray(array(
'modules.' . $lowerModuleName . '.agavi.action.path' => $module_variable . '/${moduleName}/actions/${actionName}Action.class.php',
'modules.' . $lowerModuleName . '.agavi.cache.path' => $module_variable . '/${moduleName}/cache/${actionName}.xml',
'modules.' . $lowerModuleName . '.agavi.template.directory' => $module_variable . '/${module}/templates',
'modules.' . $lowerModuleName . '.agavi.validate.path' => $module_variable . '/${moduleName}/validate/${actionName}.xml',
'modules.' . $lowerModuleName . '.agavi.view.path' => $module_variable . '/${moduleName}/views/${viewName}View.class.php',
'modules.' . $lowerModuleName . '.agavi.view.name' => '${actionName}${viewName}',
));
// include the module configuration
// loaded only once due to the way load() (former import()) works
if(is_readable($module_path . '/' . $moduleName . '/config/module.xml')) {
include_once(AgaviConfigCache::checkConfig($module_path . '/' . $moduleName . '/config/module.xml'));
} else {
AgaviConfig::set('modules.' . $lowerModuleName . '.enabled', true);
}
AgaviConfig::set('modules.' . $lowerModuleName . '.path', $module_path . '/' . $moduleName);
$moduleAutoload = $module_path . '/' . $moduleName . '/config/autoload.xml';
if(is_readable($moduleAutoload)) {
Agavi::$autoloads = array_merge(Agavi::$autoloads, include(AgaviConfigCache::checkConfig($moduleAutoload)));
}
if(AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
$moduleConfigHandlers = $module_path . '/' . $moduleName . '/config/config_handlers.xml';
if(is_readable($moduleConfigHandlers)) {
AgaviConfigCache::addConfigHandlersFile($moduleConfigHandlers);
}
}
}
if(!AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
throw new AgaviDisabledModuleException(sprintf('The module "%1$s" is disabled.', $moduleName));
}
// check for a module config.php
$moduleConfig = $module_path . '/' . $moduleName . '/config.php';
if(is_readable($moduleConfig)) {
require_once($moduleConfig);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment