public
Last active

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.