mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00: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:
parent
effaef6bdd
commit
8d3a82a4fa
8 changed files with 34 additions and 7 deletions
|
@ -112,6 +112,7 @@ services:
|
||||||
ext.manager:
|
ext.manager:
|
||||||
class: phpbb_extension_manager
|
class: phpbb_extension_manager
|
||||||
arguments:
|
arguments:
|
||||||
|
- @service_container
|
||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
- @config
|
- @config
|
||||||
- %tables.ext%
|
- %tables.ext%
|
||||||
|
|
|
@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base class for extensions without custom enable/disable/purge code.
|
* 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
|
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
|
* Single enable step that does nothing
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The extension manager provides means to activate/deactivate extensions.
|
* The extension manager provides means to activate/deactivate extensions.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +24,9 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
class phpbb_extension_manager
|
class phpbb_extension_manager
|
||||||
{
|
{
|
||||||
|
/** @var ContainerInterface */
|
||||||
|
protected $container;
|
||||||
|
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $config;
|
protected $config;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
@ -34,6 +39,7 @@ class phpbb_extension_manager
|
||||||
/**
|
/**
|
||||||
* Creates a manager and loads information from database
|
* Creates a manager and loads information from database
|
||||||
*
|
*
|
||||||
|
* @param ContainerInterface $container A container
|
||||||
* @param phpbb_db_driver $db A database connection
|
* @param phpbb_db_driver $db A database connection
|
||||||
* @param phpbb_config $config phpbb_config
|
* @param phpbb_config $config phpbb_config
|
||||||
* @param string $extension_table The name of the table holding extensions
|
* @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 phpbb_cache_driver_interface $cache A cache instance or null
|
||||||
* @param string $cache_name The name of the cache variable, defaults to _ext
|
* @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->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -126,11 +133,11 @@ class phpbb_extension_manager
|
||||||
|
|
||||||
if (class_exists($extension_class_name))
|
if (class_exists($extension_class_name))
|
||||||
{
|
{
|
||||||
return new $extension_class_name;
|
return new $extension_class_name($this->container);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new phpbb_extension_base;
|
return new phpbb_extension_base($this->container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,12 +685,12 @@ function _write_result($no_updates, $errored, $error_ary)
|
||||||
|
|
||||||
function _add_modules($modules_to_install)
|
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
|
// modules require an extension manager
|
||||||
if (empty($phpbb_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);
|
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
|
||||||
|
|
|
@ -1456,12 +1456,12 @@ class install_install extends module
|
||||||
*/
|
*/
|
||||||
function add_modules($mode, $sub)
|
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
|
// modules require an extension manager
|
||||||
if (empty($phpbb_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);
|
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
|
||||||
|
|
|
@ -26,6 +26,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->extension_manager = new phpbb_extension_manager(
|
$this->extension_manager = new phpbb_extension_manager(
|
||||||
|
new phpbb_mock_container_builder(),
|
||||||
$this->new_dbal(),
|
$this->new_dbal(),
|
||||||
new phpbb_config(array()),
|
new phpbb_config(array()),
|
||||||
'phpbb_ext',
|
'phpbb_ext',
|
||||||
|
@ -90,6 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||||
public function test_enabled_no_cache()
|
public function test_enabled_no_cache()
|
||||||
{
|
{
|
||||||
$extension_manager = new phpbb_extension_manager(
|
$extension_manager = new phpbb_extension_manager(
|
||||||
|
new phpbb_mock_container_builder(),
|
||||||
$this->new_dbal(),
|
$this->new_dbal(),
|
||||||
new phpbb_config(array()),
|
new phpbb_config(array()),
|
||||||
'phpbb_ext',
|
'phpbb_ext',
|
||||||
|
|
|
@ -48,6 +48,7 @@ class metadata_manager_test extends phpbb_database_test_case
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->extension_manager = new phpbb_extension_manager(
|
$this->extension_manager = new phpbb_extension_manager(
|
||||||
|
new phpbb_mock_container_builder(),
|
||||||
$this->db,
|
$this->db,
|
||||||
$this->config,
|
$this->config,
|
||||||
'phpbb_ext',
|
'phpbb_ext',
|
||||||
|
|
|
@ -137,6 +137,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
if (!$this->extension_manager)
|
if (!$this->extension_manager)
|
||||||
{
|
{
|
||||||
$this->extension_manager = new phpbb_extension_manager(
|
$this->extension_manager = new phpbb_extension_manager(
|
||||||
|
new phpbb_mock_container_builder(),
|
||||||
$this->get_db(),
|
$this->get_db(),
|
||||||
new phpbb_config(array()),
|
new phpbb_config(array()),
|
||||||
self::$config['table_prefix'] . 'ext',
|
self::$config['table_prefix'] . 'ext',
|
||||||
|
|
Loading…
Add table
Reference in a new issue