[feature/module_services] Start using services for modules

This includes a module_interface and module_base for the modules.
Adding, moving, or managing modules doesn't work yet.
This commit is contained in:
Marc Alexander
2013-11-07 17:33:59 +01:00
parent 6df924ff0f
commit e3220460a9
5 changed files with 341 additions and 10 deletions

View File

@@ -65,6 +65,12 @@ class main
*/
protected $path_helper;
/**
* Board3 Modules service collection
* @var phpbb\di\service_collection
*/
protected $modules;
/**
* Constructor
* NOTE: The parameters of this method must match in order and type with
@@ -76,8 +82,10 @@ class main
* @param \phpbb\path_helper $path_helper phpBB path helper
* @param string $phpbb_root_path phpBB root path
* @param string $php_ext PHP file extension
* @param \phpbb\di\service_collection $modules Board3 Modules service
* collection
*/
public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext)
public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules)
{
global $portal_root_path;
@@ -88,6 +96,8 @@ class main
$this->path_helper = $path_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->register_modules($modules);
$this->includes_path = $phpbb_root_path . 'ext/board3/portal/portal/';
$this->root_path = $phpbb_root_path . 'ext/board3/portal/';
$portal_root_path = $this->root_path;
@@ -100,6 +110,25 @@ class main
}
}
/**
* Register list of Board3 Portal modules
*
* @param \phpbb\di\service_collection $modules Board3 Modules service
* collection
* @return void
*/
protected function register_modules($modules)
{
foreach ($modules as $current_module)
{
$class_name = '\\' . get_class($current_module);
if (!isset($this->modules[$class_name]))
{
$this->modules[$class_name] = $current_module;
}
}
}
/**
* Extension front handler method. This is called automatically when your extension is accessed
* through index.php?ext=example/foobar
@@ -145,18 +174,16 @@ class main
continue;
}
$class_name = 'portal_' . $row['module_classname'] . '_module';
if (!class_exists($class_name))
// Do not try to load non-existant modules
if (!isset($this->modules[$row['module_classname']]))
{
include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}");
continue;
}
if (!class_exists($class_name))
else
{
trigger_error(sprintf($this->user->lang['CLASS_NOT_FOUND'], $class_name, 'portal_' . $row['module_classname']), E_USER_ERROR);
$module = $this->modules[$row['module_classname']];
}
$module = new $class_name();
/**
* Check for permissions before loading anything
* the default group of a user always defines his/her permission (KISS)
@@ -167,9 +194,9 @@ class main
continue;
}
if ($module->language)
if ($language_file = $module->get_language())
{
$this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->language);
$this->user->add_lang_ext('board3/portal', 'mods/portal/' . $language_file);
}
if ($row['module_column'] == column_string_num('left') && $this->config['board3_left_column'])
{