mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-01 03:54:56 +02:00
[feature/bootstrap-dic] Bootstrap container from config.php
PHPBB3-11651
This commit is contained in:
parent
bdd1d4d132
commit
1a5d685f45
@ -20,6 +20,67 @@ if (!defined('IN_PHPBB'))
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get DB connection from config.php.
|
||||||
|
*
|
||||||
|
* Used to bootstrap the container.
|
||||||
|
*
|
||||||
|
* @param string $config_file
|
||||||
|
* @return phpbb_db_driver
|
||||||
|
*/
|
||||||
|
function phpbb_bootstrap_db_connection($config_file)
|
||||||
|
{
|
||||||
|
require($config_file);
|
||||||
|
$dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
|
return new $dbal_driver_class($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get table prefix from config.php.
|
||||||
|
*
|
||||||
|
* Used to bootstrap the container.
|
||||||
|
*
|
||||||
|
* @param string $config_file
|
||||||
|
* @return string table prefix
|
||||||
|
*/
|
||||||
|
function phpbb_bootstrap_table_prefix($config_file)
|
||||||
|
{
|
||||||
|
require($config_file);
|
||||||
|
return $table_prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get enabled extensions.
|
||||||
|
*
|
||||||
|
* Used to bootstrap the container.
|
||||||
|
*
|
||||||
|
* @param string $config_file
|
||||||
|
* @return array enabled extensions
|
||||||
|
*/
|
||||||
|
function phpbb_bootstrap_enabled_exts($config_file)
|
||||||
|
{
|
||||||
|
$db = phpbb_bootstrap_db_connection($config_file);
|
||||||
|
$table_prefix = phpbb_bootstrap_table_prefix($config_file);
|
||||||
|
$extension_table = $table_prefix.'ext';
|
||||||
|
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM ' . $extension_table . '
|
||||||
|
WHERE ext_active = 1';
|
||||||
|
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
$rows = $db->sql_fetchrowset($result);
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$exts = array();
|
||||||
|
foreach ($rows as $row)
|
||||||
|
{
|
||||||
|
$exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $exts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the ContainerBuilder object
|
* Create the ContainerBuilder object
|
||||||
*
|
*
|
||||||
@ -79,16 +140,9 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext)
|
|||||||
* @param string $php_ext PHP Extension
|
* @param string $php_ext PHP Extension
|
||||||
* @return ContainerBuilder object (compiled)
|
* @return ContainerBuilder object (compiled)
|
||||||
*/
|
*/
|
||||||
function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
// Create a temporary container for access to the ext.manager service
|
$installed_exts = phpbb_bootstrap_enabled_exts($config_file);
|
||||||
$tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext);
|
|
||||||
$tmp_container->compile();
|
|
||||||
|
|
||||||
// XXX stop writing to global $cache when
|
|
||||||
// http://tracker.phpbb.com/browse/PHPBB3-11203 is fixed
|
|
||||||
$GLOBALS['cache'] = $tmp_container->get('cache');
|
|
||||||
$installed_exts = $tmp_container->get('ext.manager')->all_enabled();
|
|
||||||
|
|
||||||
// Now pass the enabled extension paths into the ext compiler extension
|
// Now pass the enabled extension paths into the ext compiler extension
|
||||||
$extensions[] = new phpbb_di_extension_ext($installed_exts);
|
$extensions[] = new phpbb_di_extension_ext($installed_exts);
|
||||||
@ -115,7 +169,7 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb
|
|||||||
* @param string $php_ext PHP Extension
|
* @param string $php_ext PHP Extension
|
||||||
* @return ContainerBuilder object (compiled)
|
* @return ContainerBuilder object (compiled)
|
||||||
*/
|
*/
|
||||||
function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
// Check for our cached container; if it exists, use it
|
// Check for our cached container; if it exists, use it
|
||||||
$container_filename = phpbb_container_filename($phpbb_root_path, $php_ext);
|
$container_filename = phpbb_container_filename($phpbb_root_path, $php_ext);
|
||||||
@ -155,7 +209,7 @@ function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_
|
|||||||
* @param string $php_ext PHP Extension
|
* @param string $php_ext PHP Extension
|
||||||
* @return ContainerBuilder object (compiled)
|
* @return ContainerBuilder object (compiled)
|
||||||
*/
|
*/
|
||||||
function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$container_factory = defined('DEBUG') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container';
|
$container_factory = defined('DEBUG') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container';
|
||||||
return $container_factory($extensions, $passes, $phpbb_root_path, $php_ext);
|
return $container_factory($extensions, $passes, $phpbb_root_path, $php_ext);
|
||||||
@ -172,9 +226,11 @@ function phpbb_create_dumped_container_unless_debug(array $extensions, array $pa
|
|||||||
*/
|
*/
|
||||||
function phpbb_create_default_container($phpbb_root_path, $php_ext)
|
function phpbb_create_default_container($phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
|
$config_file = $phpbb_root_path . 'config.' . $php_ext;
|
||||||
return phpbb_create_dumped_container_unless_debug(
|
return phpbb_create_dumped_container_unless_debug(
|
||||||
|
$config_file,
|
||||||
array(
|
array(
|
||||||
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $php_ext),
|
new phpbb_di_extension_config($config_file),
|
||||||
new phpbb_di_extension_core($phpbb_root_path),
|
new phpbb_di_extension_core($phpbb_root_path),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -40,11 +40,12 @@ class phpbb_di_container_test extends phpbb_test_case
|
|||||||
public function test_phpbb_create_compiled_container()
|
public function test_phpbb_create_compiled_container()
|
||||||
{
|
{
|
||||||
$phpbb_root_path = __DIR__ . '/../../phpBB/';
|
$phpbb_root_path = __DIR__ . '/../../phpBB/';
|
||||||
|
$config_file = __DIR__ . '/fixtures/config.php';
|
||||||
$extensions = array(
|
$extensions = array(
|
||||||
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
|
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
|
||||||
new phpbb_di_extension_core($phpbb_root_path),
|
new phpbb_di_extension_core($phpbb_root_path),
|
||||||
);
|
);
|
||||||
$container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php');
|
$container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php');
|
||||||
|
|
||||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
||||||
$this->assertTrue($container->isFrozen());
|
$this->assertTrue($container->isFrozen());
|
||||||
|
@ -84,7 +84,10 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
|||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
$this->template->clear_cache();
|
if ($this->template)
|
||||||
|
{
|
||||||
|
$this->template->clear_cache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())
|
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user