[feature/dic] Introduce DI processors instead of abusing compiler passes

PHPBB3-10739
This commit is contained in:
Igor Wiedler 2012-07-21 20:42:07 +02:00
parent 40af25115b
commit 967cc550ed
5 changed files with 38 additions and 14 deletions

View file

@ -77,7 +77,8 @@ 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/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $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);
@ -94,9 +95,8 @@ $phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config'));
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_compiler = new Compiler(); $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx);
$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); $processor->process($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

@ -43,7 +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/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $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);
@ -55,9 +56,8 @@ if (isset($_GET['avatar']))
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_compiler = new Compiler(); $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx);
$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); $processor->process($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

@ -15,12 +15,13 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
class phpbb_di_compiler_config_pass implements CompilerPassInterface class phpbb_di_processor_config implements phpbb_di_processor_interface
{ {
private $config_file; private $config_file;
private $phpbb_root_path;
private $php_ext;
public function __construct($config_file, $phpbb_root_path, $php_ext) public function __construct($config_file, $phpbb_root_path, $php_ext)
{ {

View file

@ -0,0 +1,23 @@
<?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\ContainerBuilder;
interface phpbb_di_processor_interface
{
public function process(ContainerBuilder $container);
}

View file

@ -76,7 +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/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
@ -90,9 +91,8 @@ $phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yml'); $loader->load('services.yml');
$phpbb_compiler = new Compiler(); $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx);
$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); $processor->process($phpbb_container);
$phpbb_compiler->compile($phpbb_container);
$phpbb_container->setAlias('cache.driver.install', 'cache.driver'); $phpbb_container->setAlias('cache.driver.install', 'cache.driver');