From 32d2ee61f78e3aeaac5f4f1bcb672c67aa10b10e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 16:14:21 +0200 Subject: [PATCH] [feature/dic] Configure container via config.php, use compiler pass PHPBB3-10739 --- phpBB/common.php | 21 ++++----- phpBB/config/parameters.yml | 12 ----- phpBB/config/services.yml | 1 + phpBB/config/tables.yml | 3 ++ phpBB/download/file.php | 14 ++++-- phpBB/includes/di/compiler/config_pass.php | 51 ++++++++++++++++++++++ phpBB/install/index.php | 15 +++++-- 7 files changed, 87 insertions(+), 30 deletions(-) delete mode 100644 phpBB/config/parameters.yml create mode 100644 phpBB/config/tables.yml create mode 100644 phpBB/includes/di/compiler/config_pass.php diff --git a/phpBB/common.php b/phpBB/common.php index a69b26c006..e7dabec4ca 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,6 +8,11 @@ * 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')) @@ -15,11 +20,6 @@ if (!defined('IN_PHPBB')) 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); if (file_exists($phpbb_root_path . 'config.' . $phpEx)) @@ -77,25 +77,26 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files 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_content.' . $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); + // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); -$loader->load('parameters.yml'); $loader->load('services.yml'); -$phpbb_container->setParameter('core.root_path', $phpbb_root_path); -$phpbb_container->setParameter('core.php_ext', $phpEx); -$phpbb_container->set('container', $phpbb_container); +$phpbb_compiler = new Compiler(); +$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); +$phpbb_compiler->compile($phpbb_container); // Setup class loader first $phpbb_class_loader = $phpbb_container->get('class_loader'); diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml deleted file mode 100644 index 3c24382fc4..0000000000 --- a/phpBB/config/parameters.yml +++ /dev/null @@ -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 diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 0141641aaf..20f9d67dd0 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,4 +1,5 @@ imports: + - { resource: tables.yml } - { resource: cron_tasks.yml } services: diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml new file mode 100644 index 0000000000..cfc6dbcfed --- /dev/null +++ b/phpBB/config/tables.yml @@ -0,0 +1,3 @@ +parameters: + tables.config: %core.table_prefix%config + tables.ext: %core.table_prefix%ext diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 7213e3ac3f..d4960dad0d 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -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 */ @@ -38,6 +43,8 @@ if (isset($_GET['avatar'])) } 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/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -46,12 +53,11 @@ if (isset($_GET['avatar'])) $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); - $loader->load('parameters.yml'); $loader->load('services.yml'); - $phpbb_container->setParameter('core.root_path', $phpbb_root_path); - $phpbb_container->setParameter('core.php_ext', $phpEx); - $phpbb_container->set('container', $phpbb_container); + $phpbb_compiler = new Compiler(); + $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); + $phpbb_compiler->compile($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); diff --git a/phpBB/includes/di/compiler/config_pass.php b/phpBB/includes/di/compiler/config_pass.php new file mode 100644 index 0000000000..9288c1760c --- /dev/null +++ b/phpBB/includes/di/compiler/config_pass.php @@ -0,0 +1,51 @@ +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); + } +} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 88745b8bb9..3e14b719e8 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -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 */ @@ -71,6 +76,8 @@ else // Include essential scripts 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); phpbb_require_updated('includes/functions_content.' . $phpEx, true); @@ -81,13 +88,13 @@ require($phpbb_root_path . 'includes/functions_install.' . $phpEx); $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); -$loader->load('parameters.yml'); $loader->load('services.yml'); -$phpbb_container->setParameter('core.root_path', $phpbb_root_path); -$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_compiler = new Compiler(); +$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->set('container', $phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');