[feature/dic] Configure container via config.php, use compiler pass

PHPBB3-10739
This commit is contained in:
Igor Wiedler 2012-07-21 16:14:21 +02:00
parent 5d57caee58
commit 32d2ee61f7
7 changed files with 87 additions and 30 deletions

View file

@ -8,6 +8,11 @@
* Minimum Requirement: PHP 5.3.2 * Minimum Requirement: PHP 5.3.2
*/ */
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/** /**
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
@ -15,11 +20,6 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\EventDispatcher\EventDispatcher;
require($phpbb_root_path . 'includes/startup.' . $phpEx); require($phpbb_root_path . 'includes/startup.' . $phpEx);
if (file_exists($phpbb_root_path . 'config.' . $phpEx)) if (file_exists($phpbb_root_path . 'config.' . $phpEx))
@ -77,25 +77,26 @@ if (!empty($load_extensions) && function_exists('dl'))
// Include files // Include files
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_content.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
// Set PHP error handler to ours // Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
$phpbb_container = new ContainerBuilder(); $phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config'));
$loader->load('parameters.yml');
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_container->setParameter('core.root_path', $phpbb_root_path); $phpbb_compiler = new Compiler();
$phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx));
$phpbb_container->set('container', $phpbb_container); $phpbb_compiler->compile($phpbb_container);
// Setup class loader first // Setup class loader first
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader = $phpbb_container->get('class_loader');

View file

@ -1,12 +0,0 @@
parameters:
core.table_prefix: phpbb_
cache.driver.class: phpbb_cache_driver_file
dbal.driver.class: dbal_mysqli
dbal.dbhost:
dbal.dbuser: root
dbal.dbpasswd:
dbal.dbname: phpbb
dbal.dbport:
dbal.new_link: false
tables.config: %core.table_prefix%config
tables.ext: %core.table_prefix%ext

View file

@ -1,4 +1,5 @@
imports: imports:
- { resource: tables.yml }
- { resource: cron_tasks.yml } - { resource: cron_tasks.yml }
services: services:

3
phpBB/config/tables.yml Normal file
View file

@ -0,0 +1,3 @@
parameters:
tables.config: %core.table_prefix%config
tables.ext: %core.table_prefix%ext

View file

@ -7,6 +7,11 @@
* *
*/ */
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/** /**
* @ignore * @ignore
*/ */
@ -38,6 +43,8 @@ if (isset($_GET['avatar']))
} }
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
@ -46,12 +53,11 @@ if (isset($_GET['avatar']))
$phpbb_container = new ContainerBuilder(); $phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config'));
$loader->load('parameters.yml');
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_container->setParameter('core.root_path', $phpbb_root_path); $phpbb_compiler = new Compiler();
$phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx));
$phpbb_container->set('container', $phpbb_container); $phpbb_compiler->compile($phpbb_container);
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader = $phpbb_container->get('class_loader');
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');

View file

@ -0,0 +1,51 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class phpbb_di_compiler_config_pass implements CompilerPassInterface
{
private $config_file;
public function __construct($config_file, $phpbb_root_path, $php_ext)
{
$this->config_file = $config_file;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
public function process(ContainerBuilder $container)
{
require $this->config_file;
$container->setParameter('core.root_path', $this->phpbb_root_path);
$container->setParameter('core.php_ext', $this->php_ext);
$container->setParameter('core.table_prefix', $table_prefix);
$container->setParameter('cache.driver.class', $acm_type);
$container->setParameter('dbal.driver.class', $dbms);
$container->setParameter('dbal.dbhost', $dbhost);
$container->setParameter('dbal.dbuser', $dbuser);
$container->setParameter('dbal.dbpasswd', $dbpasswd);
$container->setParameter('dbal.dbname', $dbname);
$container->setParameter('dbal.dbport', $dbport);
$container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK);
$container->set('container', $container);
}
}

View file

@ -7,6 +7,11 @@
* *
*/ */
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**#@+ /**#@+
* @ignore * @ignore
*/ */
@ -71,6 +76,8 @@ else
// Include essential scripts // Include essential scripts
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
phpbb_require_updated('includes/functions_content.' . $phpEx, true); phpbb_require_updated('includes/functions_content.' . $phpEx, true);
@ -81,13 +88,13 @@ require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
$phpbb_container = new ContainerBuilder(); $phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config'));
$loader->load('parameters.yml');
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_container->setParameter('core.root_path', $phpbb_root_path); $phpbb_compiler = new Compiler();
$phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx));
$phpbb_compiler->compile($phpbb_container);
$phpbb_container->setAlias('cache.driver.install', 'cache.driver'); $phpbb_container->setAlias('cache.driver.install', 'cache.driver');
$phpbb_container->set('container', $phpbb_container);
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader = $phpbb_container->get('class_loader');
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');