From cdf87e0078e3c4d78bfd1b9d12100eb1451b5633 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 26 Jun 2014 16:39:01 +0200 Subject: [ticket/12775] Add a conter_factory class and remove functions_container PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 361 +++++++++++++++++++++++++++++++++++ phpBB/phpbb/di/extension/config.php | 9 +- 2 files changed, 367 insertions(+), 3 deletions(-) create mode 100644 phpBB/phpbb/di/container_factory.php (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php new file mode 100644 index 0000000000..aeea025b94 --- /dev/null +++ b/phpBB/phpbb/di/container_factory.php @@ -0,0 +1,361 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Dumper\PhpDumper; + +class container_factory +{ + /** @var string phpBB Root Path */ + protected $phpbb_root_path; + + /** @var string php file extension */ + protected $php_ext; + + /** + * The container under construction + * + * @var ContainerInterface + */ + protected $container = null; + + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $dbal_connection = null; + + /** + * @var array the installed extensions + */ + protected $installed_exts = null; + + /** + * Indicates if the php config file has been loaded. + * + * @var bool + */ + protected $config_loaded = false; + + /** + * The content of the php config file + * + * @var array + */ + protected $config_data = array(); + + /** + * Indicates if the php config file should be injecting into the container (default to true). + * + * @var bool + */ + protected $inject_config = true; + + /** + * Indicates if the extensions should be used (default to true). + * + * @var bool + */ + protected $use_extensions = true; + + /** + * Defines a custom path to find the configuration of the container. + * + * @var string + */ + protected $config_path = null; + + /** + * Indicates if the phpBB compile pass have to be used (default to true). + * + * @var bool + */ + protected $use_custom_pass = true; + + /** + * Indicates if a dump container should be used (default to true). + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @var bool + */ + protected $dump_container = true; + + /** + * Constructor + * + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + */ + function __construct($phpbb_root_path, $php_ext) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Build and return a new Container respecting the current configuration + * + * @return \phpbb_cache_container|ContainerBuilder + */ + public function get_container() + { + $container_filename = $this->get_container_filename(); + if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) + { + require($container_filename); + $this->container = new \phpbb_cache_container(); + } + else + { + if ($this->config_path === null) + { + $config_path = $this->phpbb_root_path . 'config'; + } + $container_extensions = array(new \phpbb\di\extension\core($config_path)); + + if ($this->use_extensions) + { + $installed_exts = $this->get_installed_extensions(); + $container_extensions[] = new \phpbb\di\extension\ext($installed_exts); + } + + if ($this->inject_config) + { + $this->load_config_file(); + $container_extensions[] = new \phpbb\di\extension\config($this->config_data); + } + + $this->container = $this->create_container($container_extensions); + + if ($this->use_custom_pass) + { + $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); + $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + } + + $this->container->setParameter('core.root_path', $this->phpbb_root_path); + $this->container->setParameter('core.php_ext', $this->php_ext); + + $this->container->compile(); + + if ($this->dump_container && defined('DEBUG')) + { + $this->dump_container($container_filename); + } + } + + // Impossible because we have a compiled (and so frozen) container + /*if ($this->inject_config) + { + $this->inject_config(); + }*/ + + // Frozen container, we can't modify either the services or the parameters + //$this->inject_dbal(); + + return $this->container; + } + + /** + * Load the config file, store the information and return them + * + * @return bool|array Return the content of the config file or false if the file does not exists. + */ + public function load_config_file() + { + if (!$this->config_loaded) + { + if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) + { + $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = null; + $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = get_defined_vars(); + + require($this->phpbb_root_path . 'config.' . $this->php_ext); + $this->config_data = array_diff_key(get_defined_vars(), $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb); + + $this->config_loaded = true; + } + else + { + return false; + } + } + + return $this->config_data; + } + + /** + * Set if the extensions should be used. + * + * @param bool $use_extensions + */ + public function set_use_extensions($use_extensions) + { + $this->use_extensions = $use_extensions; + } + + /** + * Set if the phpBB compile pass have to be used. + * + * @param bool $use_custom_pass + */ + public function set_use_customPass($use_custom_pass) + { + $this->use_custom_pass = $use_custom_pass; + } + + /** + * Set if the php config file should be injecting into the container. + * + * @param bool $inject_config + */ + public function set_inject_config($inject_config) + { + $this->inject_config = $inject_config; + } + + /** + * Set if a dump container should be used. + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @var bool $dump_container + */ + public function setDumpContainer($dump_container) + { + $this->dump_container = $dump_container; + } + + /** + * Set a custom path to find the configuration of the container + * + * @param string $config_path + */ + public function setConfigPath($config_path) + { + $this->config_path = $config_path; + } + + /** + * Dump the container to the disk. + * + * @param string $container_filename The name of the file. + */ + protected function dump_container($container_filename) + { + // Lastly, we create our cached container class + $dumper = new PhpDumper($this->container); + $cached_container_dump = $dumper->dump(array( + 'class' => 'phpbb_cache_container', + 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', + )); + + file_put_contents($container_filename, $cached_container_dump); + } + + /** + * Inject the connection into the container if one was opened. + */ + protected function inject_dbal() + { + if ($this->dbal_connection !== null) + { + $this->container->set('dbal.conn', $this->dbal_connection); + } + } + + /** + * Get DB connection. + * + * @return \phpbb\db\driver\driver_interface + */ + protected function get_dbal_connection() + { + if ($this->dbal_connection === null) + { + $this->load_config_file(); + $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_data['dbms']); + $this->dbal_connection = new $dbal_driver_class(); + $this->dbal_connection->sql_connect( + $this->config_data['dbhost'], + $this->config_data['dbuser'], + $this->config_data['dbpasswd'], + $this->config_data['dbname'], + $this->config_data['dbport'], + defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK + ); + } + + return $this->dbal_connection; + } + + /** + * Get enabled extensions. + * + * @return array enabled extensions + */ + protected function get_installed_extensions() + { + $db = $this->get_dbal_connection(); + $extension_table = $this->config_data['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']] = $this->phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; + } + + return $exts; + } + + /** + * Create the ContainerBuilder object + * + * @param array $extensions Array of Container extension objects + * @return ContainerBuilder object + */ + protected function create_container(array $extensions) + { + $container = new ContainerBuilder(); + + foreach ($extensions as $extension) + { + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + + return $container; + } + + /** + * Get the filename under which the dumped container will be stored. + * + * @return string Path for dumped container + */ + protected function get_container_filename() + { + $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); + return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext; + } +} diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index a7d7284f85..8a26d44858 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -21,9 +21,12 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; */ class config extends Extension { - public function __construct($config_file) + /** @var array */ + protected $config_file_data; + + public function __construct($config_file_data) { - $this->config_file = $config_file; + $this->config_file_data = $config_file_data; } /** @@ -36,7 +39,7 @@ class config extends Extension */ public function load(array $config, ContainerBuilder $container) { - require($this->config_file); + extract($this->config_file_data); $container->setParameter('core.adm_relative_path', (isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/')); $container->setParameter('core.table_prefix', $table_prefix); -- cgit v1.2.1 From 86205454afb0b851534f7309c668dc092863c8ce Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:10:18 +0200 Subject: [ticket/12775] Add customs parameters PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index aeea025b94..a9bc0ea7f7 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -93,6 +93,19 @@ class container_factory */ protected $dump_container = true; + /** + * Custom parameters to inject into the container. + * + * Default to true: + * array( + * 'core.root_path', $this->phpbb_root_path, + * 'core.php_ext', $this->php_ext, + * ); + * + * @var array + */ + protected $custom_parameters = null; + /** * Constructor * @@ -146,8 +159,7 @@ class container_factory $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); } - $this->container->setParameter('core.root_path', $this->phpbb_root_path); - $this->container->setParameter('core.php_ext', $this->php_ext); + $this->inject_custom_parameters(); $this->container->compile(); @@ -234,7 +246,7 @@ class container_factory * * @var bool $dump_container */ - public function setDumpContainer($dump_container) + public function set_dump_container($dump_container) { $this->dump_container = $dump_container; } @@ -244,11 +256,21 @@ class container_factory * * @param string $config_path */ - public function setConfigPath($config_path) + public function set_config_path($config_path) { $this->config_path = $config_path; } + /** + * Set custom parameters to inject into the container. + * + * @param array $custom_parameters + */ + public function set_custom_parameters($custom_parameters) + { + $this->custom_parameters = $custom_parameters; + } + /** * Dump the container to the disk. * @@ -348,6 +370,25 @@ class container_factory return $container; } + /** + * Inject the customs parameters into the container + */ + protected function inject_custom_parameters() + { + if ($this->custom_parameters === null) + { + $this->custom_parameters = array( + 'core.root_path', $this->phpbb_root_path, + 'core.php_ext', $this->php_ext, + ); + } + + foreach ($this->custom_parameters as $key => $value) + { + $this->container->setParameter($key, $value); + } + } + /** * Get the filename under which the dumped container will be stored. * -- cgit v1.2.1 From cbe846a64eb73b99d11320c79678dd6dcb58b44b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:17:27 +0200 Subject: [ticket/12775] Don't assign $container to null PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index a9bc0ea7f7..50844ba5d0 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -30,7 +30,7 @@ class container_factory * * @var ContainerInterface */ - protected $container = null; + protected $container; /** * @var \phpbb\db\driver\driver_interface -- cgit v1.2.1 From 301d9ce9902a35fb8015805882723ab382f30ef4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:39:47 +0200 Subject: [ticket/12775] Add a config.php class (and service) PHPBB3-12775 --- phpBB/phpbb/config_php.php | 77 ++++++++++++++++++++++++++++++++++++ phpBB/phpbb/di/container_factory.php | 57 +++++--------------------- 2 files changed, 87 insertions(+), 47 deletions(-) create mode 100644 phpBB/phpbb/config_php.php (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php new file mode 100644 index 0000000000..a92950909d --- /dev/null +++ b/phpBB/phpbb/config_php.php @@ -0,0 +1,77 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb; + +class config_php +{ + /** @var string phpBB Root Path */ + protected $phpbb_root_path; + + /** @var string php file extension */ + protected $php_ext; + + /** + * Indicates if the php config file has been loaded. + * + * @var bool + */ + protected $config_loaded = false; + + /** + * The content of the php config file + * + * @var array + */ + protected $config_data = array(); + + /** + * Constructor + * + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + */ + function __construct($phpbb_root_path, $php_ext) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Load the config file, store the information and return them + * + * @return bool|array Return the content of the config file or false if the file does not exists. + */ + public function load_config_file() + { + if (!$this->config_loaded) + { + if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) + { + $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = null; + $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = get_defined_vars(); + + require($this->phpbb_root_path . 'config.' . $this->php_ext); + $this->config_data = array_diff_key(get_defined_vars(), $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb); + + $this->config_loaded = true; + } + else + { + return false; + } + } + + return $this->config_data; + } +} diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index 50844ba5d0..37fe9f486f 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -42,13 +42,6 @@ class container_factory */ protected $installed_exts = null; - /** - * Indicates if the php config file has been loaded. - * - * @var bool - */ - protected $config_loaded = false; - /** * The content of the php config file * @@ -109,11 +102,13 @@ class container_factory /** * Constructor * + * @param \phpbb\config_php $config_php_handler * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension */ - function __construct($phpbb_root_path, $php_ext) + function __construct(\phpbb\config_php $config_php_handler, $phpbb_root_path, $php_ext) { + $this->config_php_handler = $config_php_handler; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } @@ -135,9 +130,9 @@ class container_factory { if ($this->config_path === null) { - $config_path = $this->phpbb_root_path . 'config'; + $this->config_path = $this->phpbb_root_path . 'config'; } - $container_extensions = array(new \phpbb\di\extension\core($config_path)); + $container_extensions = array(new \phpbb\di\extension\core($this->config_path)); if ($this->use_extensions) { @@ -147,7 +142,7 @@ class container_factory if ($this->inject_config) { - $this->load_config_file(); + $this->config_data = $this->config_php_handler->load_config_file(); $container_extensions[] = new \phpbb\di\extension\config($this->config_data); } @@ -169,11 +164,7 @@ class container_factory } } - // Impossible because we have a compiled (and so frozen) container - /*if ($this->inject_config) - { - $this->inject_config(); - }*/ + $this->container->set('config.php', $this->config_php_handler); // Frozen container, we can't modify either the services or the parameters //$this->inject_dbal(); @@ -181,34 +172,6 @@ class container_factory return $this->container; } - /** - * Load the config file, store the information and return them - * - * @return bool|array Return the content of the config file or false if the file does not exists. - */ - public function load_config_file() - { - if (!$this->config_loaded) - { - if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) - { - $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = null; - $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = get_defined_vars(); - - require($this->phpbb_root_path . 'config.' . $this->php_ext); - $this->config_data = array_diff_key(get_defined_vars(), $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb); - - $this->config_loaded = true; - } - else - { - return false; - } - } - - return $this->config_data; - } - /** * Set if the extensions should be used. * @@ -308,7 +271,7 @@ class container_factory { if ($this->dbal_connection === null) { - $this->load_config_file(); + $this->config_data = $this->config_php_handler->load_config_file(); $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_data['dbms']); $this->dbal_connection = new $dbal_driver_class(); $this->dbal_connection->sql_connect( @@ -378,8 +341,8 @@ class container_factory if ($this->custom_parameters === null) { $this->custom_parameters = array( - 'core.root_path', $this->phpbb_root_path, - 'core.php_ext', $this->php_ext, + 'core.root_path' => $this->phpbb_root_path, + 'core.php_ext' => $this->php_ext, ); } -- cgit v1.2.1 From b9995405cf1c2694c0b4848e43c9de0454717b27 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:03:01 +0200 Subject: [ticket/12775] Add get() and get_all() into config_php PHPBB3-12775 --- phpBB/phpbb/config_php.php | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index a92950909d..a4af4e6a6e 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -48,21 +48,52 @@ class config_php } /** - * Load the config file, store the information and return them + * Returns an array containing all the variables defined into the config.php file * * @return bool|array Return the content of the config file or false if the file does not exists. */ - public function load_config_file() + public function get_all() + { + if (!$this->load_config_file()) + { + return false; + } + + return $this->config_data; + } + + /** + * Return the value of a variable defined into the config.php file and false if the variable does not exist. + * + * @param string $variable The name of the variable + * @return mixed + */ + public function get($variable) + { + if (!$this->load_config_file()) + { + return false; + } + + return isset($this->config_data[$variable]) ? $this->config_data[$variable] : false; + } + + /** + * Load the config file and store the information. + * + * @return bool True if the file was correctly loaded, false otherwise. + */ + protected function load_config_file() { if (!$this->config_loaded) { if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) { - $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = null; - $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb = get_defined_vars(); + $defined_vars = null; + $defined_vars = get_defined_vars(); require($this->phpbb_root_path . 'config.' . $this->php_ext); - $this->config_data = array_diff_key(get_defined_vars(), $x7eeee37ce4d5f1ce4d968ed8fdd9bcbb); + $this->config_data = array_diff_key(get_defined_vars(), $defined_vars); $this->config_loaded = true; } @@ -71,7 +102,5 @@ class config_php return false; } } - - return $this->config_data; } } -- cgit v1.2.1 From 01c25d3d6b1d09389a6cbd5808832ed5d146b6d6 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:08:26 +0200 Subject: [ticket/12775] Use the config.php handler in \phpbb\config_php PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 25 ++++++++----------------- phpBB/phpbb/di/extension/config.php | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 30 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index 37fe9f486f..dd348d8eee 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -42,13 +42,6 @@ class container_factory */ protected $installed_exts = null; - /** - * The content of the php config file - * - * @var array - */ - protected $config_data = array(); - /** * Indicates if the php config file should be injecting into the container (default to true). * @@ -142,8 +135,7 @@ class container_factory if ($this->inject_config) { - $this->config_data = $this->config_php_handler->load_config_file(); - $container_extensions[] = new \phpbb\di\extension\config($this->config_data); + $container_extensions[] = new \phpbb\di\extension\config($this->config_php_handler); } $this->container = $this->create_container($container_extensions); @@ -271,15 +263,14 @@ class container_factory { if ($this->dbal_connection === null) { - $this->config_data = $this->config_php_handler->load_config_file(); - $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_data['dbms']); + $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms')); $this->dbal_connection = new $dbal_driver_class(); $this->dbal_connection->sql_connect( - $this->config_data['dbhost'], - $this->config_data['dbuser'], - $this->config_data['dbpasswd'], - $this->config_data['dbname'], - $this->config_data['dbport'], + $this->config_php_handler->get('dbhost'), + $this->config_php_handler->get('dbuser'), + $this->config_php_handler->get('dbpasswd'), + $this->config_php_handler->get('dbname'), + $this->config_php_handler->get('dbport'), defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK ); } @@ -295,7 +286,7 @@ class container_factory protected function get_installed_extensions() { $db = $this->get_dbal_connection(); - $extension_table = $this->config_data['table_prefix'] . 'ext'; + $extension_table = $this->config_php_handler->get('table_prefix') . 'ext'; $sql = 'SELECT * FROM ' . $extension_table . ' diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 8a26d44858..b25635d7ae 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -22,11 +22,11 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; class config extends Extension { /** @var array */ - protected $config_file_data; + protected $config_php; - public function __construct($config_file_data) + public function __construct(\phpbb\config_php $config_php) { - $this->config_file_data = $config_file_data; + $this->config_php = $config_php; } /** @@ -39,17 +39,15 @@ class config extends Extension */ public function load(array $config, ContainerBuilder $container) { - extract($this->config_file_data); - $container->setParameter('core.adm_relative_path', (isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/')); - $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $this->convert_30_acm_type($acm_type)); - $container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($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('core.table_prefix', $this->config_php->get('table_prefix')); + $container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type'))); + $container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($this->config_php->get('dbms'))); + $container->setParameter('dbal.dbhost', $this->config_php->get('dbhost')); + $container->setParameter('dbal.dbuser', $this->config_php->get('dbuser')); + $container->setParameter('dbal.dbpasswd', $this->config_php->get('dbpasswd')); + $container->setParameter('dbal.dbname', $this->config_php->get('dbname')); + $container->setParameter('dbal.dbport', $this->config_php->get('dbport')); $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); } -- cgit v1.2.1 From 98890fe1a3e9ad94f8eb8883f1973f3bbc27a124 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:40:19 +0200 Subject: [ticket/12775] Fix config_php::load_config_file() PHPBB3-12775 --- phpBB/phpbb/config_php.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index a4af4e6a6e..13ca533ade 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -102,5 +102,6 @@ class config_php return false; } } + return true; } } -- cgit v1.2.1 From 78648514fa8b847cfb63cd4b5432d3fa73dd106f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:41:16 +0200 Subject: [ticket/12775] Update phpBB/bin/phpbbcli.php PHPBB3-12775 --- phpBB/phpbb/config_php.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index 13ca533ade..d502088897 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -102,6 +102,7 @@ class config_php return false; } } + return true; } } -- cgit v1.2.1 From e7804ecce4511d8befdcc28f6705c3589c47c878 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:02:20 +0200 Subject: [ticket/12775] Update phpBB/install/database_update.php PHPBB3-12775 --- phpBB/phpbb/config_php.php | 23 +++++++++++++++++++++-- phpBB/phpbb/di/container_factory.php | 25 +++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index d502088897..31a84662fa 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -35,6 +35,13 @@ class config_php */ protected $config_data = array(); + /** + * The path to the config file. (Defaults: $phpbb_root_path . 'config.' . $php_ext) + * + * @var string + */ + protected $config_file; + /** * Constructor * @@ -45,6 +52,18 @@ class config_php { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->config_file = $this->phpbb_root_path . 'config.' . $this->php_ext; + } + + /** + * Set the path to the config file. + * + * @param string $config_file + */ + public function set_config_file($config_file) + { + $this->config_file = $config_file; + $this->config_loaded = false; } /** @@ -87,12 +106,12 @@ class config_php { if (!$this->config_loaded) { - if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) + if (file_exists($this->config_file)) { $defined_vars = null; $defined_vars = get_defined_vars(); - require($this->phpbb_root_path . 'config.' . $this->php_ext); + require($this->config_file); $this->config_data = array_diff_key(get_defined_vars(), $defined_vars); $this->config_loaded = true; diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index dd348d8eee..548bbf153f 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -70,6 +70,13 @@ class container_factory */ protected $use_custom_pass = true; + /** + * Indicates if the kernel compile pass have to be used (default to true). + * + * @var bool + */ + protected $use_kernel_pass = true; + /** * Indicates if a dump container should be used (default to true). * @@ -143,7 +150,11 @@ class container_factory if ($this->use_custom_pass) { $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); - $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + + if ($this->use_kernel_pass) + { + $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + } } $this->inject_custom_parameters(); @@ -179,11 +190,21 @@ class container_factory * * @param bool $use_custom_pass */ - public function set_use_customPass($use_custom_pass) + public function set_use_custom_pass($use_custom_pass) { $this->use_custom_pass = $use_custom_pass; } + /** + * Set if the kernel compile pass have to be used. + * + * @param bool $use_kernel_pass + */ + public function set_use_kernel_pass($use_kernel_pass) + { + $this->use_kernel_pass = $use_kernel_pass; + } + /** * Set if the php config file should be injecting into the container. * -- cgit v1.2.1 From ef1346c931a2ddd095d5dbf296cb598dca6edfe8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:27:55 +0200 Subject: [ticket/12775] Update phpBB/install/index.php PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index 548bbf153f..a83c79f517 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -14,7 +14,6 @@ namespace phpbb\di; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; class container_factory @@ -28,7 +27,7 @@ class container_factory /** * The container under construction * - * @var ContainerInterface + * @var ContainerBuilder */ protected $container; @@ -86,6 +85,13 @@ class container_factory */ protected $dump_container = true; + /** + * Indicates if the container should be compiled automatically (default to true). + * + * @var bool + */ + protected $compile_container = true; + /** * Custom parameters to inject into the container. * @@ -159,7 +165,10 @@ class container_factory $this->inject_custom_parameters(); - $this->container->compile(); + if ($this->compile_container) + { + $this->container->compile(); + } if ($this->dump_container && defined('DEBUG')) { @@ -227,6 +236,16 @@ class container_factory $this->dump_container = $dump_container; } + /** + * Set if the container should be compiled automatically (default to true). + * + * @var bool $dump_container + */ + public function set_compile_container($compile_container) + { + $this->compile_container = $compile_container; + } + /** * Set a custom path to find the configuration of the container * -- cgit v1.2.1 From c87f44c6692c55adb3ce5bc5b7bca8da7b1357ab Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 23:29:43 +0200 Subject: [ticket/12775] Use a field instead of a local var in load_config_var() PHPBB3-12775 --- phpBB/phpbb/config_php.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index 31a84662fa..8191023437 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -108,11 +108,11 @@ class config_php { if (file_exists($this->config_file)) { - $defined_vars = null; - $defined_vars = get_defined_vars(); + $this->defined_vars = null; + $this->defined_vars = get_defined_vars(); require($this->config_file); - $this->config_data = array_diff_key(get_defined_vars(), $defined_vars); + $this->config_data = array_diff_key(get_defined_vars(), $this->defined_vars); $this->config_loaded = true; } -- cgit v1.2.1 From 1d966fbc86db47c3518b35de849cad3a1f295e71 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 28 Jun 2014 01:36:59 +0200 Subject: [ticket/12775] Add tests for the container factory PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index a83c79f517..426c411e07 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -170,7 +170,7 @@ class container_factory $this->container->compile(); } - if ($this->dump_container && defined('DEBUG')) + if ($this->dump_container && !defined('DEBUG')) { $this->dump_container($container_filename); } -- cgit v1.2.1 From 40937e21c58399a847d04f23423622b0e1894446 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:29:08 +0200 Subject: [ticket/12775] Renamed to \phpbb\di\container_builder PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 396 +++++++++++++++++++++++++++++++++++ phpBB/phpbb/di/container_factory.php | 396 ----------------------------------- 2 files changed, 396 insertions(+), 396 deletions(-) create mode 100644 phpBB/phpbb/di/container_builder.php delete mode 100644 phpBB/phpbb/di/container_factory.php (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php new file mode 100644 index 0000000000..426c411e07 --- /dev/null +++ b/phpBB/phpbb/di/container_builder.php @@ -0,0 +1,396 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Dumper\PhpDumper; + +class container_factory +{ + /** @var string phpBB Root Path */ + protected $phpbb_root_path; + + /** @var string php file extension */ + protected $php_ext; + + /** + * The container under construction + * + * @var ContainerBuilder + */ + protected $container; + + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $dbal_connection = null; + + /** + * @var array the installed extensions + */ + protected $installed_exts = null; + + /** + * Indicates if the php config file should be injecting into the container (default to true). + * + * @var bool + */ + protected $inject_config = true; + + /** + * Indicates if the extensions should be used (default to true). + * + * @var bool + */ + protected $use_extensions = true; + + /** + * Defines a custom path to find the configuration of the container. + * + * @var string + */ + protected $config_path = null; + + /** + * Indicates if the phpBB compile pass have to be used (default to true). + * + * @var bool + */ + protected $use_custom_pass = true; + + /** + * Indicates if the kernel compile pass have to be used (default to true). + * + * @var bool + */ + protected $use_kernel_pass = true; + + /** + * Indicates if a dump container should be used (default to true). + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @var bool + */ + protected $dump_container = true; + + /** + * Indicates if the container should be compiled automatically (default to true). + * + * @var bool + */ + protected $compile_container = true; + + /** + * Custom parameters to inject into the container. + * + * Default to true: + * array( + * 'core.root_path', $this->phpbb_root_path, + * 'core.php_ext', $this->php_ext, + * ); + * + * @var array + */ + protected $custom_parameters = null; + + /** + * Constructor + * + * @param \phpbb\config_php $config_php_handler + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + */ + function __construct(\phpbb\config_php $config_php_handler, $phpbb_root_path, $php_ext) + { + $this->config_php_handler = $config_php_handler; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Build and return a new Container respecting the current configuration + * + * @return \phpbb_cache_container|ContainerBuilder + */ + public function get_container() + { + $container_filename = $this->get_container_filename(); + if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) + { + require($container_filename); + $this->container = new \phpbb_cache_container(); + } + else + { + if ($this->config_path === null) + { + $this->config_path = $this->phpbb_root_path . 'config'; + } + $container_extensions = array(new \phpbb\di\extension\core($this->config_path)); + + if ($this->use_extensions) + { + $installed_exts = $this->get_installed_extensions(); + $container_extensions[] = new \phpbb\di\extension\ext($installed_exts); + } + + if ($this->inject_config) + { + $container_extensions[] = new \phpbb\di\extension\config($this->config_php_handler); + } + + $this->container = $this->create_container($container_extensions); + + if ($this->use_custom_pass) + { + $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); + + if ($this->use_kernel_pass) + { + $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + } + } + + $this->inject_custom_parameters(); + + if ($this->compile_container) + { + $this->container->compile(); + } + + if ($this->dump_container && !defined('DEBUG')) + { + $this->dump_container($container_filename); + } + } + + $this->container->set('config.php', $this->config_php_handler); + + // Frozen container, we can't modify either the services or the parameters + //$this->inject_dbal(); + + return $this->container; + } + + /** + * Set if the extensions should be used. + * + * @param bool $use_extensions + */ + public function set_use_extensions($use_extensions) + { + $this->use_extensions = $use_extensions; + } + + /** + * Set if the phpBB compile pass have to be used. + * + * @param bool $use_custom_pass + */ + public function set_use_custom_pass($use_custom_pass) + { + $this->use_custom_pass = $use_custom_pass; + } + + /** + * Set if the kernel compile pass have to be used. + * + * @param bool $use_kernel_pass + */ + public function set_use_kernel_pass($use_kernel_pass) + { + $this->use_kernel_pass = $use_kernel_pass; + } + + /** + * Set if the php config file should be injecting into the container. + * + * @param bool $inject_config + */ + public function set_inject_config($inject_config) + { + $this->inject_config = $inject_config; + } + + /** + * Set if a dump container should be used. + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @var bool $dump_container + */ + public function set_dump_container($dump_container) + { + $this->dump_container = $dump_container; + } + + /** + * Set if the container should be compiled automatically (default to true). + * + * @var bool $dump_container + */ + public function set_compile_container($compile_container) + { + $this->compile_container = $compile_container; + } + + /** + * Set a custom path to find the configuration of the container + * + * @param string $config_path + */ + public function set_config_path($config_path) + { + $this->config_path = $config_path; + } + + /** + * Set custom parameters to inject into the container. + * + * @param array $custom_parameters + */ + public function set_custom_parameters($custom_parameters) + { + $this->custom_parameters = $custom_parameters; + } + + /** + * Dump the container to the disk. + * + * @param string $container_filename The name of the file. + */ + protected function dump_container($container_filename) + { + // Lastly, we create our cached container class + $dumper = new PhpDumper($this->container); + $cached_container_dump = $dumper->dump(array( + 'class' => 'phpbb_cache_container', + 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', + )); + + file_put_contents($container_filename, $cached_container_dump); + } + + /** + * Inject the connection into the container if one was opened. + */ + protected function inject_dbal() + { + if ($this->dbal_connection !== null) + { + $this->container->set('dbal.conn', $this->dbal_connection); + } + } + + /** + * Get DB connection. + * + * @return \phpbb\db\driver\driver_interface + */ + protected function get_dbal_connection() + { + if ($this->dbal_connection === null) + { + $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms')); + $this->dbal_connection = new $dbal_driver_class(); + $this->dbal_connection->sql_connect( + $this->config_php_handler->get('dbhost'), + $this->config_php_handler->get('dbuser'), + $this->config_php_handler->get('dbpasswd'), + $this->config_php_handler->get('dbname'), + $this->config_php_handler->get('dbport'), + defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK + ); + } + + return $this->dbal_connection; + } + + /** + * Get enabled extensions. + * + * @return array enabled extensions + */ + protected function get_installed_extensions() + { + $db = $this->get_dbal_connection(); + $extension_table = $this->config_php_handler->get('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']] = $this->phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; + } + + return $exts; + } + + /** + * Create the ContainerBuilder object + * + * @param array $extensions Array of Container extension objects + * @return ContainerBuilder object + */ + protected function create_container(array $extensions) + { + $container = new ContainerBuilder(); + + foreach ($extensions as $extension) + { + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + + return $container; + } + + /** + * Inject the customs parameters into the container + */ + protected function inject_custom_parameters() + { + if ($this->custom_parameters === null) + { + $this->custom_parameters = array( + 'core.root_path' => $this->phpbb_root_path, + 'core.php_ext' => $this->php_ext, + ); + } + + foreach ($this->custom_parameters as $key => $value) + { + $this->container->setParameter($key, $value); + } + } + + /** + * Get the filename under which the dumped container will be stored. + * + * @return string Path for dumped container + */ + protected function get_container_filename() + { + $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); + return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext; + } +} diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php deleted file mode 100644 index 426c411e07..0000000000 --- a/phpBB/phpbb/di/container_factory.php +++ /dev/null @@ -1,396 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Dumper\PhpDumper; - -class container_factory -{ - /** @var string phpBB Root Path */ - protected $phpbb_root_path; - - /** @var string php file extension */ - protected $php_ext; - - /** - * The container under construction - * - * @var ContainerBuilder - */ - protected $container; - - /** - * @var \phpbb\db\driver\driver_interface - */ - protected $dbal_connection = null; - - /** - * @var array the installed extensions - */ - protected $installed_exts = null; - - /** - * Indicates if the php config file should be injecting into the container (default to true). - * - * @var bool - */ - protected $inject_config = true; - - /** - * Indicates if the extensions should be used (default to true). - * - * @var bool - */ - protected $use_extensions = true; - - /** - * Defines a custom path to find the configuration of the container. - * - * @var string - */ - protected $config_path = null; - - /** - * Indicates if the phpBB compile pass have to be used (default to true). - * - * @var bool - */ - protected $use_custom_pass = true; - - /** - * Indicates if the kernel compile pass have to be used (default to true). - * - * @var bool - */ - protected $use_kernel_pass = true; - - /** - * Indicates if a dump container should be used (default to true). - * - * If DEBUG_CONTAINER is set this option is ignored and a new container is build. - * - * @var bool - */ - protected $dump_container = true; - - /** - * Indicates if the container should be compiled automatically (default to true). - * - * @var bool - */ - protected $compile_container = true; - - /** - * Custom parameters to inject into the container. - * - * Default to true: - * array( - * 'core.root_path', $this->phpbb_root_path, - * 'core.php_ext', $this->php_ext, - * ); - * - * @var array - */ - protected $custom_parameters = null; - - /** - * Constructor - * - * @param \phpbb\config_php $config_php_handler - * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension - */ - function __construct(\phpbb\config_php $config_php_handler, $phpbb_root_path, $php_ext) - { - $this->config_php_handler = $config_php_handler; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Build and return a new Container respecting the current configuration - * - * @return \phpbb_cache_container|ContainerBuilder - */ - public function get_container() - { - $container_filename = $this->get_container_filename(); - if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) - { - require($container_filename); - $this->container = new \phpbb_cache_container(); - } - else - { - if ($this->config_path === null) - { - $this->config_path = $this->phpbb_root_path . 'config'; - } - $container_extensions = array(new \phpbb\di\extension\core($this->config_path)); - - if ($this->use_extensions) - { - $installed_exts = $this->get_installed_extensions(); - $container_extensions[] = new \phpbb\di\extension\ext($installed_exts); - } - - if ($this->inject_config) - { - $container_extensions[] = new \phpbb\di\extension\config($this->config_php_handler); - } - - $this->container = $this->create_container($container_extensions); - - if ($this->use_custom_pass) - { - $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); - - if ($this->use_kernel_pass) - { - $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); - } - } - - $this->inject_custom_parameters(); - - if ($this->compile_container) - { - $this->container->compile(); - } - - if ($this->dump_container && !defined('DEBUG')) - { - $this->dump_container($container_filename); - } - } - - $this->container->set('config.php', $this->config_php_handler); - - // Frozen container, we can't modify either the services or the parameters - //$this->inject_dbal(); - - return $this->container; - } - - /** - * Set if the extensions should be used. - * - * @param bool $use_extensions - */ - public function set_use_extensions($use_extensions) - { - $this->use_extensions = $use_extensions; - } - - /** - * Set if the phpBB compile pass have to be used. - * - * @param bool $use_custom_pass - */ - public function set_use_custom_pass($use_custom_pass) - { - $this->use_custom_pass = $use_custom_pass; - } - - /** - * Set if the kernel compile pass have to be used. - * - * @param bool $use_kernel_pass - */ - public function set_use_kernel_pass($use_kernel_pass) - { - $this->use_kernel_pass = $use_kernel_pass; - } - - /** - * Set if the php config file should be injecting into the container. - * - * @param bool $inject_config - */ - public function set_inject_config($inject_config) - { - $this->inject_config = $inject_config; - } - - /** - * Set if a dump container should be used. - * - * If DEBUG_CONTAINER is set this option is ignored and a new container is build. - * - * @var bool $dump_container - */ - public function set_dump_container($dump_container) - { - $this->dump_container = $dump_container; - } - - /** - * Set if the container should be compiled automatically (default to true). - * - * @var bool $dump_container - */ - public function set_compile_container($compile_container) - { - $this->compile_container = $compile_container; - } - - /** - * Set a custom path to find the configuration of the container - * - * @param string $config_path - */ - public function set_config_path($config_path) - { - $this->config_path = $config_path; - } - - /** - * Set custom parameters to inject into the container. - * - * @param array $custom_parameters - */ - public function set_custom_parameters($custom_parameters) - { - $this->custom_parameters = $custom_parameters; - } - - /** - * Dump the container to the disk. - * - * @param string $container_filename The name of the file. - */ - protected function dump_container($container_filename) - { - // Lastly, we create our cached container class - $dumper = new PhpDumper($this->container); - $cached_container_dump = $dumper->dump(array( - 'class' => 'phpbb_cache_container', - 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', - )); - - file_put_contents($container_filename, $cached_container_dump); - } - - /** - * Inject the connection into the container if one was opened. - */ - protected function inject_dbal() - { - if ($this->dbal_connection !== null) - { - $this->container->set('dbal.conn', $this->dbal_connection); - } - } - - /** - * Get DB connection. - * - * @return \phpbb\db\driver\driver_interface - */ - protected function get_dbal_connection() - { - if ($this->dbal_connection === null) - { - $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms')); - $this->dbal_connection = new $dbal_driver_class(); - $this->dbal_connection->sql_connect( - $this->config_php_handler->get('dbhost'), - $this->config_php_handler->get('dbuser'), - $this->config_php_handler->get('dbpasswd'), - $this->config_php_handler->get('dbname'), - $this->config_php_handler->get('dbport'), - defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK - ); - } - - return $this->dbal_connection; - } - - /** - * Get enabled extensions. - * - * @return array enabled extensions - */ - protected function get_installed_extensions() - { - $db = $this->get_dbal_connection(); - $extension_table = $this->config_php_handler->get('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']] = $this->phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; - } - - return $exts; - } - - /** - * Create the ContainerBuilder object - * - * @param array $extensions Array of Container extension objects - * @return ContainerBuilder object - */ - protected function create_container(array $extensions) - { - $container = new ContainerBuilder(); - - foreach ($extensions as $extension) - { - $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); - } - - return $container; - } - - /** - * Inject the customs parameters into the container - */ - protected function inject_custom_parameters() - { - if ($this->custom_parameters === null) - { - $this->custom_parameters = array( - 'core.root_path' => $this->phpbb_root_path, - 'core.php_ext' => $this->php_ext, - ); - } - - foreach ($this->custom_parameters as $key => $value) - { - $this->container->setParameter($key, $value); - } - } - - /** - * Get the filename under which the dumped container will be stored. - * - * @return string Path for dumped container - */ - protected function get_container_filename() - { - $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); - return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext; - } -} -- cgit v1.2.1 From 2db160ff87fa42ca6c47e580de9bc9d7e5cced49 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:33:31 +0200 Subject: [ticket/12775] Rename config_php to config_php_file PHPBB3-12775 --- phpBB/phpbb/config_php.php | 127 ----------------------------------- phpBB/phpbb/config_php_file.php | 127 +++++++++++++++++++++++++++++++++++ phpBB/phpbb/di/container_builder.php | 4 +- phpBB/phpbb/di/extension/config.php | 2 +- 4 files changed, 130 insertions(+), 130 deletions(-) delete mode 100644 phpBB/phpbb/config_php.php create mode 100644 phpBB/phpbb/config_php_file.php (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php deleted file mode 100644 index 8191023437..0000000000 --- a/phpBB/phpbb/config_php.php +++ /dev/null @@ -1,127 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb; - -class config_php -{ - /** @var string phpBB Root Path */ - protected $phpbb_root_path; - - /** @var string php file extension */ - protected $php_ext; - - /** - * Indicates if the php config file has been loaded. - * - * @var bool - */ - protected $config_loaded = false; - - /** - * The content of the php config file - * - * @var array - */ - protected $config_data = array(); - - /** - * The path to the config file. (Defaults: $phpbb_root_path . 'config.' . $php_ext) - * - * @var string - */ - protected $config_file; - - /** - * Constructor - * - * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension - */ - function __construct($phpbb_root_path, $php_ext) - { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->config_file = $this->phpbb_root_path . 'config.' . $this->php_ext; - } - - /** - * Set the path to the config file. - * - * @param string $config_file - */ - public function set_config_file($config_file) - { - $this->config_file = $config_file; - $this->config_loaded = false; - } - - /** - * Returns an array containing all the variables defined into the config.php file - * - * @return bool|array Return the content of the config file or false if the file does not exists. - */ - public function get_all() - { - if (!$this->load_config_file()) - { - return false; - } - - return $this->config_data; - } - - /** - * Return the value of a variable defined into the config.php file and false if the variable does not exist. - * - * @param string $variable The name of the variable - * @return mixed - */ - public function get($variable) - { - if (!$this->load_config_file()) - { - return false; - } - - return isset($this->config_data[$variable]) ? $this->config_data[$variable] : false; - } - - /** - * Load the config file and store the information. - * - * @return bool True if the file was correctly loaded, false otherwise. - */ - protected function load_config_file() - { - if (!$this->config_loaded) - { - if (file_exists($this->config_file)) - { - $this->defined_vars = null; - $this->defined_vars = get_defined_vars(); - - require($this->config_file); - $this->config_data = array_diff_key(get_defined_vars(), $this->defined_vars); - - $this->config_loaded = true; - } - else - { - return false; - } - } - - return true; - } -} diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php new file mode 100644 index 0000000000..5a2fbca0dd --- /dev/null +++ b/phpBB/phpbb/config_php_file.php @@ -0,0 +1,127 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb; + +class config_php_file +{ + /** @var string phpBB Root Path */ + protected $phpbb_root_path; + + /** @var string php file extension */ + protected $php_ext; + + /** + * Indicates if the php config file has been loaded. + * + * @var bool + */ + protected $config_loaded = false; + + /** + * The content of the php config file + * + * @var array + */ + protected $config_data = array(); + + /** + * The path to the config file. (Defaults: $phpbb_root_path . 'config.' . $php_ext) + * + * @var string + */ + protected $config_file; + + /** + * Constructor + * + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + */ + function __construct($phpbb_root_path, $php_ext) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config_file = $this->phpbb_root_path . 'config.' . $this->php_ext; + } + + /** + * Set the path to the config file. + * + * @param string $config_file + */ + public function set_config_file($config_file) + { + $this->config_file = $config_file; + $this->config_loaded = false; + } + + /** + * Returns an array containing all the variables defined into the config.php file + * + * @return bool|array Return the content of the config file or false if the file does not exists. + */ + public function get_all() + { + if (!$this->load_config_file()) + { + return false; + } + + return $this->config_data; + } + + /** + * Return the value of a variable defined into the config.php file and false if the variable does not exist. + * + * @param string $variable The name of the variable + * @return mixed + */ + public function get($variable) + { + if (!$this->load_config_file()) + { + return false; + } + + return isset($this->config_data[$variable]) ? $this->config_data[$variable] : false; + } + + /** + * Load the config file and store the information. + * + * @return bool True if the file was correctly loaded, false otherwise. + */ + protected function load_config_file() + { + if (!$this->config_loaded) + { + if (file_exists($this->config_file)) + { + $this->defined_vars = null; + $this->defined_vars = get_defined_vars(); + + require($this->config_file); + $this->config_data = array_diff_key(get_defined_vars(), $this->defined_vars); + + $this->config_loaded = true; + } + else + { + return false; + } + } + + return true; + } +} diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 426c411e07..355d975a5f 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -108,11 +108,11 @@ class container_factory /** * Constructor * - * @param \phpbb\config_php $config_php_handler + * @param \phpbb\config_php_file $config_php_handler * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension */ - function __construct(\phpbb\config_php $config_php_handler, $phpbb_root_path, $php_ext) + function __construct(\phpbb\config_php_file $config_php_handler, $phpbb_root_path, $php_ext) { $this->config_php_handler = $config_php_handler; $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index b25635d7ae..4176df9227 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -24,7 +24,7 @@ class config extends Extension /** @var array */ protected $config_php; - public function __construct(\phpbb\config_php $config_php) + public function __construct(\phpbb\config_php_file $config_php) { $this->config_php = $config_php; } -- cgit v1.2.1 From f2e8e928c08809202b1abf5668a46e3d9e735c38 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:35:46 +0200 Subject: [ticket/12775] Fix container_builder PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 355d975a5f..f78b9e60f8 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -16,7 +16,7 @@ namespace phpbb\di; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -class container_factory +class container_builder { /** @var string phpBB Root Path */ protected $phpbb_root_path; -- cgit v1.2.1 From 15c23e60b8e4b78c68286ae76e03a12b81393159 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 18:39:19 +0200 Subject: [ticket/12775] Update doc blocks PHPBB3-12775 --- phpBB/phpbb/config_php_file.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index 5a2fbca0dd..ba8d3a0d9d 100644 --- a/phpBB/phpbb/config_php_file.php +++ b/phpBB/phpbb/config_php_file.php @@ -22,7 +22,7 @@ class config_php_file protected $php_ext; /** - * Indicates if the php config file has been loaded. + * Indicates whether the php config file has been loaded. * * @var bool */ @@ -36,7 +36,7 @@ class config_php_file protected $config_data = array(); /** - * The path to the config file. (Defaults: $phpbb_root_path . 'config.' . $php_ext) + * The path to the config file. (Default: $phpbb_root_path . 'config.' . $php_ext) * * @var string */ @@ -45,7 +45,7 @@ class config_php_file /** * Constructor * - * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $phpbb_root_path phpBB Root Path * @param string $php_ext php file extension */ function __construct($phpbb_root_path, $php_ext) @@ -67,7 +67,7 @@ class config_php_file } /** - * Returns an array containing all the variables defined into the config.php file + * Returns an associative array containing the variables defined by the config file. * * @return bool|array Return the content of the config file or false if the file does not exists. */ -- cgit v1.2.1 From 98e8be966bd8174c2a3f4e8fb80167b23573441f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 21:47:00 +0200 Subject: [ticket/12775] Fix comments PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 1 - phpBB/phpbb/di/extension/config.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index f78b9e60f8..fbbe736e47 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -273,7 +273,6 @@ class container_builder */ protected function dump_container($container_filename) { - // Lastly, we create our cached container class $dumper = new PhpDumper($this->container); $cached_container_dump = $dumper->dump(array( 'class' => 'phpbb_cache_container', diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 4176df9227..ec2d7f6e44 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -39,7 +39,7 @@ class config extends Extension */ public function load(array $config, ContainerBuilder $container) { - $container->setParameter('core.adm_relative_path', (isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/')); + $container->setParameter('core.adm_relative_path', ($this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/')); $container->setParameter('core.table_prefix', $this->config_php->get('table_prefix')); $container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type'))); $container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($this->config_php->get('dbms'))); -- cgit v1.2.1 From ed812a9dfb59b1eb83263adbaa52723ff826a791 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 21:58:17 +0200 Subject: [ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class PHPBB3-12775 --- phpBB/phpbb/config_php_file.php | 47 ++++++++++++++++++++++++++++++++++++ phpBB/phpbb/di/container_builder.php | 2 +- phpBB/phpbb/di/extension/config.php | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index ba8d3a0d9d..c0aa3567e6 100644 --- a/phpBB/phpbb/config_php_file.php +++ b/phpBB/phpbb/config_php_file.php @@ -124,4 +124,51 @@ class config_php_file return true; } + + /** + * Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name. + * + * If $dbms is a valid 3.1 db driver class name, returns it unchanged. + * Otherwise prepends phpbb\db\driver\ to the dbms to convert a 3.0 dbms + * to 3.1 db driver class name. + * + * @param string $dbms dbms parameter + * @return string driver class + * @throws \RuntimeException + */ + public function convert_30_dbms_to_31($dbms) + { + // Note: this check is done first because mysqli extension + // supplies a mysqli class, and class_exists($dbms) would return + // true for mysqli class. + // However, per the docblock any valid 3.1 driver name should be + // recognized by this function, and have priority over 3.0 dbms. + if (strpos($dbms, 'phpbb\db\driver') === false && class_exists('phpbb\db\driver\\' . $dbms)) + { + return 'phpbb\db\driver\\' . $dbms; + } + + if (class_exists($dbms)) + { + // Additionally we could check that $dbms extends phpbb\db\driver\driver. + // http://php.net/manual/en/class.reflectionclass.php + // Beware of possible performance issues: + // http://stackoverflow.com/questions/294582/php-5-reflection-api-performance + // We could check for interface implementation in all paths or + // only when we do not prepend phpbb\db\driver\. + + /* + $reflection = new \ReflectionClass($dbms); + + if ($reflection->isSubclassOf('phpbb\db\driver\driver')) + { + return $dbms; + } + */ + + return $dbms; + } + + throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); + } } diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index fbbe736e47..95b82b26c7 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -302,7 +302,7 @@ class container_builder { if ($this->dbal_connection === null) { - $dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms')); + $dbal_driver_class = $this->config_php_handler->convert_30_dbms_to_31($this->config_php_handler->get('dbms')); $this->dbal_connection = new $dbal_driver_class(); $this->dbal_connection->sql_connect( $this->config_php_handler->get('dbhost'), diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index ec2d7f6e44..27ebc94bae 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -42,7 +42,7 @@ class config extends Extension $container->setParameter('core.adm_relative_path', ($this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/')); $container->setParameter('core.table_prefix', $this->config_php->get('table_prefix')); $container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type'))); - $container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($this->config_php->get('dbms'))); + $container->setParameter('dbal.driver.class', $this->config_php->convert_30_dbms_to_31($this->config_php->get('dbms'))); $container->setParameter('dbal.dbhost', $this->config_php->get('dbhost')); $container->setParameter('dbal.dbuser', $this->config_php->get('dbuser')); $container->setParameter('dbal.dbpasswd', $this->config_php->get('dbpasswd')); -- cgit v1.2.1 From 35c0b6d77ac1f42c1e76b7c15469b025cd50845e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 00:51:28 +0200 Subject: [ticket/12775] Fix doc blocks in the container builder PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 95b82b26c7..4b6fb6d20b 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -42,42 +42,42 @@ class container_builder protected $installed_exts = null; /** - * Indicates if the php config file should be injecting into the container (default to true). + * Indicates whether the php config file should be injected into the container (default to true). * * @var bool */ protected $inject_config = true; /** - * Indicates if the extensions should be used (default to true). + * Indicates whether extensions should be used (default to true). * * @var bool */ protected $use_extensions = true; /** - * Defines a custom path to find the configuration of the container. + * Defines a custom path to find the configuration of the container (default to $this->phpbb_root_path . 'config') * * @var string */ protected $config_path = null; /** - * Indicates if the phpBB compile pass have to be used (default to true). + * Indicates whether the phpBB compile pass should be used (default to true). * * @var bool */ protected $use_custom_pass = true; /** - * Indicates if the kernel compile pass have to be used (default to true). + * Indicates whether the kernel compile pass should be used (default to true). * * @var bool */ protected $use_kernel_pass = true; /** - * Indicates if a dump container should be used (default to true). + * Indicates whether the container should be dumped to the filesystem (default to true). * * If DEBUG_CONTAINER is set this option is ignored and a new container is build. * @@ -105,16 +105,21 @@ class container_builder */ protected $custom_parameters = null; + /** + * @var \phpbb\config_php_file + */ + protected $config_php_file; + /** * Constructor * - * @param \phpbb\config_php_file $config_php_handler + * @param \phpbb\config_php_file $config_php_file * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension */ - function __construct(\phpbb\config_php_file $config_php_handler, $phpbb_root_path, $php_ext) + function __construct(\phpbb\config_php_file $config_php_file, $phpbb_root_path, $php_ext) { - $this->config_php_handler = $config_php_handler; + $this->config_php_file = $config_php_file; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } -- cgit v1.2.1 From 8c0d179e3e43c6c9e2e8e95d26c1dbdb80c26f36 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 01:01:48 +0200 Subject: [ticket/12775] Set defined_vars as a property of config_php_file PHPBB3-12775 --- phpBB/phpbb/config_php_file.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index c0aa3567e6..1a562e470d 100644 --- a/phpBB/phpbb/config_php_file.php +++ b/phpBB/phpbb/config_php_file.php @@ -42,6 +42,8 @@ class config_php_file */ protected $config_file; + private $defined_vars; + /** * Constructor * @@ -108,7 +110,6 @@ class config_php_file { if (file_exists($this->config_file)) { - $this->defined_vars = null; $this->defined_vars = get_defined_vars(); require($this->config_file); -- cgit v1.2.1 From 6c57fbecac3aff2341fc874a911b3f296252ee3e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 01:05:55 +0200 Subject: [ticket/12775] Rename config_php_handler to config_php_file container_builder PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 4b6fb6d20b..9cf29c8929 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -153,7 +153,7 @@ class container_builder if ($this->inject_config) { - $container_extensions[] = new \phpbb\di\extension\config($this->config_php_handler); + $container_extensions[] = new \phpbb\di\extension\config($this->config_php_file); } $this->container = $this->create_container($container_extensions); @@ -181,7 +181,7 @@ class container_builder } } - $this->container->set('config.php', $this->config_php_handler); + $this->container->set('config.php', $this->config_php_file); // Frozen container, we can't modify either the services or the parameters //$this->inject_dbal(); @@ -307,14 +307,14 @@ class container_builder { if ($this->dbal_connection === null) { - $dbal_driver_class = $this->config_php_handler->convert_30_dbms_to_31($this->config_php_handler->get('dbms')); + $dbal_driver_class = $this->config_php_file->convert_30_dbms_to_31($this->config_php_file->get('dbms')); $this->dbal_connection = new $dbal_driver_class(); $this->dbal_connection->sql_connect( - $this->config_php_handler->get('dbhost'), - $this->config_php_handler->get('dbuser'), - $this->config_php_handler->get('dbpasswd'), - $this->config_php_handler->get('dbname'), - $this->config_php_handler->get('dbport'), + $this->config_php_file->get('dbhost'), + $this->config_php_file->get('dbuser'), + $this->config_php_file->get('dbpasswd'), + $this->config_php_file->get('dbname'), + $this->config_php_file->get('dbport'), defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK ); } @@ -330,7 +330,7 @@ class container_builder protected function get_installed_extensions() { $db = $this->get_dbal_connection(); - $extension_table = $this->config_php_handler->get('table_prefix') . 'ext'; + $extension_table = $this->config_php_file->get('table_prefix') . 'ext'; $sql = 'SELECT * FROM ' . $extension_table . ' -- cgit v1.2.1 From 5b11ee8c97e88367fc39b90b6a871e3bf16f7d1e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 4 Jul 2014 21:36:25 +0200 Subject: [ticket/12775] Inject the connection when created in the container PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 9cf29c8929..65db92ada0 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -183,8 +183,7 @@ class container_builder $this->container->set('config.php', $this->config_php_file); - // Frozen container, we can't modify either the services or the parameters - //$this->inject_dbal(); + $this->inject_dbal(); return $this->container; } @@ -294,7 +293,7 @@ class container_builder { if ($this->dbal_connection !== null) { - $this->container->set('dbal.conn', $this->dbal_connection); + $this->container->get('dbal.conn')->set_driver($this->dbal_connection); } } -- cgit v1.2.1 From e2cbaf4f1a0b0ddcba45babbe922076ff149a83d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 7 Jul 2014 00:08:34 +0200 Subject: [ticket/12775] Add the definition of dbal.conn in fixtures/config/services.yml PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 65db92ada0..ab10073013 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -183,7 +183,10 @@ class container_builder $this->container->set('config.php', $this->config_php_file); - $this->inject_dbal(); + if ($this->compile_container) + { + $this->inject_dbal(); + } return $this->container; } -- cgit v1.2.1