1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[feature/migrations] Make the container available to extension installers

This allows extensions to load and install migrations easily as per their
needs.

PHPBB3-11318
This commit is contained in:
Nathan Guse
2013-01-10 19:32:39 -06:00
parent effaef6bdd
commit 8d3a82a4fa
8 changed files with 34 additions and 7 deletions

View File

@@ -112,6 +112,7 @@ services:
ext.manager:
class: phpbb_extension_manager
arguments:
- @service_container
- @dbal.conn
- @config
- %tables.ext%

View File

@@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))
exit;
}
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* A base class for extensions without custom enable/disable/purge code.
*
@@ -22,6 +24,19 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_extension_base implements phpbb_extension_interface
{
/** @var ContainerInterface */
protected $container;
/**
* Constructor
*
* @param ContainerInterface $container Container object
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* Single enable step that does nothing
*

View File

@@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))
exit;
}
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The extension manager provides means to activate/deactivate extensions.
*
@@ -22,6 +24,9 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_extension_manager
{
/** @var ContainerInterface */
protected $container;
protected $db;
protected $config;
protected $cache;
@@ -34,6 +39,7 @@ class phpbb_extension_manager
/**
* Creates a manager and loads information from database
*
* @param ContainerInterface $container A container
* @param phpbb_db_driver $db A database connection
* @param phpbb_config $config phpbb_config
* @param string $extension_table The name of the table holding extensions
@@ -42,8 +48,9 @@ class phpbb_extension_manager
* @param phpbb_cache_driver_interface $cache A cache instance or null
* @param string $cache_name The name of the cache variable, defaults to _ext
*/
public function __construct(phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')
public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')
{
$this->container = $container;
$this->phpbb_root_path = $phpbb_root_path;
$this->db = $db;
$this->config = $config;
@@ -126,11 +133,11 @@ class phpbb_extension_manager
if (class_exists($extension_class_name))
{
return new $extension_class_name;
return new $extension_class_name($this->container);
}
else
{
return new phpbb_extension_base;
return new phpbb_extension_base($this->container);
}
}

View File

@@ -685,12 +685,12 @@ function _write_result($no_updates, $errored, $error_ary)
function _add_modules($modules_to_install)
{
global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config;
global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config, $phpbb_container;
// modules require an extension manager
if (empty($phpbb_extension_manager))
{
$phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx");
$phpbb_extension_manager = $phpbb_container->get('ext.manager');
}
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);

View File

@@ -1456,12 +1456,12 @@ class install_install extends module
*/
function add_modules($mode, $sub)
{
global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config;
global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config, $phpbb_container;
// modules require an extension manager
if (empty($phpbb_extension_manager))
{
$phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx");
$phpbb_extension_manager = $phpbb_container->get('ext.manager');
}
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);