From cdf87e0078e3c4d78bfd1b9d12100eb1451b5633 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 26 Jun 2014 16:39:01 +0200 Subject: [PATCH 01/34] [ticket/12775] Add a conter_factory class and remove functions_container PHPBB3-12775 --- phpBB/common.php | 12 +- phpBB/phpbb/di/container_factory.php | 361 +++++++++++++++++++++++++++ phpBB/phpbb/di/extension/config.php | 9 +- 3 files changed, 373 insertions(+), 9 deletions(-) create mode 100644 phpBB/phpbb/di/container_factory.php diff --git a/phpBB/common.php b/phpBB/common.php index e96a34938a9..a30b7b989f9 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -21,11 +21,11 @@ } require($phpbb_root_path . 'includes/startup.' . $phpEx); +require($phpbb_root_path . 'phpbb/di/container_factory.' . $phpEx); -if (file_exists($phpbb_root_path . 'config.' . $phpEx)) -{ - require($phpbb_root_path . 'config.' . $phpEx); -} +$factory = new \phpbb\di\container_factory($phpbb_root_path, $phpEx); +$config_file_data = $factory->load_config_file(); +extract($config_file_data); if (!defined('PHPBB_INSTALLED')) { @@ -80,7 +80,6 @@ require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); -require($phpbb_root_path . 'includes/functions_container.' . $phpEx); include($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -98,7 +97,8 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); +$phpbb_container = $factory->get_container(); + $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php new file mode 100644 index 00000000000..aeea025b94f --- /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 a7d7284f852..8a26d44858d 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -21,9 +21,12 @@ */ 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 @@ public function __construct($config_file) */ 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); From 86205454afb0b851534f7309c668dc092863c8ce Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:10:18 +0200 Subject: [PATCH 02/34] [ticket/12775] Add customs parameters PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 49 +++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index aeea025b94f..a9bc0ea7f7e 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 @@ public function get_container() $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 @@ public function set_inject_config($inject_config) * * @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 @@ public function setDumpContainer($dump_container) * * @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 @@ protected function create_container(array $extensions) 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. * From cbe846a64eb73b99d11320c79678dd6dcb58b44b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:17:27 +0200 Subject: [PATCH 03/34] [ticket/12775] Don't assign $container to null PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index a9bc0ea7f7e..50844ba5d02 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 From 301d9ce9902a35fb8015805882723ab382f30ef4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:39:47 +0200 Subject: [PATCH 04/34] [ticket/12775] Add a config.php class (and service) PHPBB3-12775 --- phpBB/common.php | 17 +++--- phpBB/config/services.yml | 3 ++ phpBB/phpbb/config_php.php | 77 ++++++++++++++++++++++++++++ phpBB/phpbb/di/container_factory.php | 57 ++++---------------- 4 files changed, 98 insertions(+), 56 deletions(-) create mode 100644 phpBB/phpbb/config_php.php diff --git a/phpBB/common.php b/phpBB/common.php index a30b7b989f9..901c0bd713a 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -21,10 +21,14 @@ } require($phpbb_root_path . 'includes/startup.' . $phpEx); -require($phpbb_root_path . 'phpbb/di/container_factory.' . $phpEx); +require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); + +// Setup class loader first +$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); +$phpbb_class_loader->register(); -$factory = new \phpbb\di\container_factory($phpbb_root_path, $phpEx); -$config_file_data = $factory->load_config_file(); +$config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +$config_file_data = $config_php_handler->load_config_file(); extract($config_file_data); if (!defined('PHPBB_INSTALLED')) @@ -76,8 +80,6 @@ $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include files -require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); include($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx); @@ -88,18 +90,15 @@ // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -// Setup class loader first -$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); -$phpbb_class_loader->register(); $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container +$factory = new \phpbb\di\container_factory($config_php_handler, $phpbb_root_path, $phpEx); $phpbb_container = $factory->get_container(); - $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 735a49c99b4..09dfc2fba2e 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -69,6 +69,9 @@ services: - @cache.driver - %tables.config% + config.php: + synthetic: true + config_text: class: phpbb\config\db_text arguments: diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php new file mode 100644 index 00000000000..a92950909d8 --- /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 50844ba5d02..37fe9f486f6 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 @@ public function get_container() { 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 @@ public function get_container() 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 @@ public function get_container() } } - // 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 @@ public function get_container() 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 @@ protected function get_dbal_connection() { 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 @@ 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, + 'core.root_path' => $this->phpbb_root_path, + 'core.php_ext' => $this->php_ext, ); } From b9995405cf1c2694c0b4848e43c9de0454717b27 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:03:01 +0200 Subject: [PATCH 05/34] [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(-) diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index a92950909d8..a4af4e6a6e6 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -48,21 +48,52 @@ function __construct($phpbb_root_path, $php_ext) } /** - * 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 @@ public function load_config_file() return false; } } - - return $this->config_data; } } From 01c25d3d6b1d09389a6cbd5808832ed5d146b6d6 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:08:26 +0200 Subject: [PATCH 06/34] [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(-) diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index 37fe9f486f6..dd348d8eee8 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 @@ public function get_container() 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 @@ protected function get_dbal_connection() { 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 @@ protected function get_dbal_connection() 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 8a26d44858d..b25635d7aea 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -22,11 +22,11 @@ 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 @@ public function __construct($config_file_data) */ 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); } From 4f56f9b90464ed23b30125a5df147577c435de9b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:10:19 +0200 Subject: [PATCH 07/34] [ticket/12775] Rename the variables into common.php PHPBB3-12775 --- phpBB/common.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 901c0bd713a..8c9e5b60239 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -27,9 +27,8 @@ $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -$config_file_data = $config_php_handler->load_config_file(); -extract($config_file_data); +$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +extract($phpbb_config_php_handler->get_all()); if (!defined('PHPBB_INSTALLED')) { @@ -96,8 +95,8 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$factory = new \phpbb\di\container_factory($config_php_handler, $phpbb_root_path, $phpEx); -$phpbb_container = $factory->get_container(); +$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container = $phpbb_container_factory->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); From 98890fe1a3e9ad94f8eb8883f1973f3bbc27a124 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:40:19 +0200 Subject: [PATCH 08/34] [ticket/12775] Fix config_php::load_config_file() PHPBB3-12775 --- phpBB/phpbb/config_php.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index a4af4e6a6e6..13ca533aded 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -102,5 +102,6 @@ protected function load_config_file() return false; } } + return true; } } From 78648514fa8b847cfb63cd4b5432d3fa73dd106f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:41:16 +0200 Subject: [PATCH 09/34] [ticket/12775] Update phpBB/bin/phpbbcli.php PHPBB3-12775 --- phpBB/bin/phpbbcli.php | 11 ++++++++--- phpBB/phpbb/config_php.php | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 8b8d8e43fd4..e6b9e3ac8d3 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -22,11 +22,9 @@ $phpbb_root_path = __DIR__ . '/../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require($phpbb_root_path . 'includes/startup.' . $phpEx); -require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); -require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); @@ -35,7 +33,14 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); -$phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, "$phpbb_root_path/config"); +$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +extract($phpbb_config_php_handler->get_all()); + +$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_factory->set_use_extensions(false); +$phpbb_container_factory->set_dump_container(false); + +$phpbb_container = $phpbb_container_factory->get_container(); $phpbb_container->get('request')->enable_super_globals(); require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx); diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index 13ca533aded..d5020888977 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -102,6 +102,7 @@ protected function load_config_file() return false; } } + return true; } } From f87e76b9109fa4da3d4c78f191cfd8889f1da1bb Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 20:45:31 +0200 Subject: [PATCH 10/34] [ticket/12775] Update phpBB/download/file.php PHPBB3-12775 --- phpBB/download/file.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index abafeee6679..636a73a95f2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -38,7 +38,6 @@ if (isset($_GET['avatar'])) { require($phpbb_root_path . 'includes/startup.' . $phpEx); - require($phpbb_root_path . 'config.' . $phpEx); if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { @@ -49,7 +48,6 @@ require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); - require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); @@ -61,8 +59,12 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); + $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); + extract($phpbb_config_php_handler->get_all()); + // Set up container - $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); + $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_factory->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); From e7804ecce4511d8befdcc28f6705c3589c47c878 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:02:20 +0200 Subject: [PATCH 11/34] [ticket/12775] Update phpBB/install/database_update.php PHPBB3-12775 --- phpBB/includes/functions_container.php | 586 ++++++++++++------------- phpBB/install/database_update.php | 36 +- phpBB/phpbb/config_php.php | 23 +- phpBB/phpbb/di/container_factory.php | 25 +- 4 files changed, 347 insertions(+), 323 deletions(-) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index a00613c26b6..96086a59ed3 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -1,297 +1,291 @@ -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** -* Get DB connection from config.php. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @return \phpbb\db\driver\driver_interface -*/ -function phpbb_bootstrap_db_connection($config_file) -{ - require($config_file); - $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); - - $db = new $dbal_driver_class(); - $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); - - return $db; -} - -/** -* Get table prefix from config.php. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @return string table prefix -*/ -function phpbb_bootstrap_table_prefix($config_file) -{ - require($config_file); - return $table_prefix; -} - -/** -* Get enabled extensions. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @param string $phpbb_root_path -* @param \phpbb\db\driver\driver_interface $db The generated connection -* @return array enabled extensions -*/ -function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path, &$db) -{ - $db = phpbb_bootstrap_db_connection($config_file); - $table_prefix = phpbb_bootstrap_table_prefix($config_file); - $extension_table = $table_prefix.'ext'; - - $sql = 'SELECT * - FROM ' . $extension_table . ' - WHERE ext_active = 1'; - - $result = $db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $exts = array(); - foreach ($rows as $row) - { - $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; - } - - return $exts; -} - -/** -* Create the ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object -*/ -function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) -{ - $container = new ContainerBuilder(); - - foreach ($extensions as $extension) - { - $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); - } - - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $php_ext); - - return $container; -} - -/** -* Create installer container -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object -*/ -function phpbb_create_install_container($phpbb_root_path, $php_ext) -{ - $other_config_path = $phpbb_root_path . 'install/update/new/config/'; - $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; - - $core = new \phpbb\di\extension\core($config_path); - $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); - - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); - $container->setParameter('core.php_ext', $php_ext); - $container->setParameter('core.table_prefix', ''); - - $container->register('dbal.conn.driver')->setSynthetic(true); - - $container->setAlias('cache.driver', 'cache.driver.install'); - - $container->compile(); - - return $container; -} - -/** -* Create updater container -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @param array $config_path Path to config directory -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) -{ - $config_file = $phpbb_root_path . 'config.' . $php_ext; - return phpbb_create_compiled_container( - $config_file, - array( - new phpbb\di\extension\config($config_file), - new phpbb\di\extension\core($config_path), - ), - array( - new phpbb\di\pass\collection_pass(), - new phpbb\di\pass\kernel_pass(), - ), - $phpbb_root_path, - $php_ext - ); -} - -/** -* Create a compiled ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - // Create the final container to be compiled and cached - $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); - - // Compile the container - foreach ($passes as $pass) - { - $container->addCompilerPass($pass); - } - $container->compile(); - - return $container; -} - -/** -* Create a compiled and dumped ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - // Check for our cached container; if it exists, use it - $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); - if (file_exists($container_filename)) - { - require($container_filename); - return new phpbb_cache_container(); - } - - $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); - - // Lastly, we create our cached container class - $dumper = new PhpDumper($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); - - return $container; -} - -/** -* Create an environment-specific ContainerBuilder object -* -* If debug is enabled, the container is re-compiled every time. -* This ensures that the latest changes will always be reflected -* during development. -* -* Otherwise it will get the existing dumped container and use -* that one instead. -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - $container_factory = defined('DEBUG_CONTAINER') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; - return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); -} - -/** -* Create a default ContainerBuilder object -* -* Contains the default configuration of the phpBB container. -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_default_container($phpbb_root_path, $php_ext) -{ - $config_file = $phpbb_root_path . 'config.' . $php_ext; - $db = null; - $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path, $db); - - $container = phpbb_create_dumped_container_unless_debug( - $config_file, - array( - new \phpbb\di\extension\config($config_file), - new \phpbb\di\extension\core($phpbb_root_path . 'config'), - new \phpbb\di\extension\ext($installed_exts), - ), - array( - new \phpbb\di\pass\collection_pass(), - new \phpbb\di\pass\kernel_pass(), - ), - $phpbb_root_path, - $php_ext - ); - - $container->get('dbal.conn')->set_driver($db); - - return $container; -} - -/** -* Get the filename under which the dumped container will be stored. -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return Path for dumped container -*/ -function phpbb_container_filename($phpbb_root_path, $php_ext) -{ - $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); - return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; -} +///** +//* +//* This file is part of the phpBB Forum Software package. +//* +//* @copyright (c) phpBB Limited +//* @license GNU General Public License, version 2 (GPL-2.0) +//* +//* For full copyright and license information, please see +//* the docs/CREDITS.txt file. +//* +//*/ +// +//use Symfony\Component\Config\FileLocator; +//use Symfony\Component\DependencyInjection\ContainerBuilder; +//use Symfony\Component\DependencyInjection\Dumper\PhpDumper; +//use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +// +///** +//* @ignore +//*/ +//if (!defined('IN_PHPBB')) +//{ +// exit; +//} +// +///** +//* Get DB connection from config.php. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @return \phpbb\db\driver\driver_interface +//*/ +//function phpbb_bootstrap_db_connection($config_file) +//{ +// require($config_file); +// $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); +// +// $db = new $dbal_driver_class(); +// $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); +// +// return $db; +//} +// +///** +//* Get table prefix from config.php. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @return string table prefix +//*/ +//function phpbb_bootstrap_table_prefix($config_file) +//{ +// require($config_file); +// return $table_prefix; +//} +// +///** +//* Get enabled extensions. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @param string $phpbb_root_path +//* @return array enabled extensions +//*/ +//function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path) +//{ +// $db = phpbb_bootstrap_db_connection($config_file); +// $table_prefix = phpbb_bootstrap_table_prefix($config_file); +// $extension_table = $table_prefix.'ext'; +// +// $sql = 'SELECT * +// FROM ' . $extension_table . ' +// WHERE ext_active = 1'; +// +// $result = $db->sql_query($sql); +// $rows = $db->sql_fetchrowset($result); +// $db->sql_freeresult($result); +// +// $exts = array(); +// foreach ($rows as $row) +// { +// $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; +// } +// +// return $exts; +//} +// +///** +//* Create the ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object +//*/ +//function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) +//{ +// $container = new ContainerBuilder(); +// +// foreach ($extensions as $extension) +// { +// $container->registerExtension($extension); +// $container->loadFromExtension($extension->getAlias()); +// } +// +// $container->setParameter('core.root_path', $phpbb_root_path); +// $container->setParameter('core.php_ext', $php_ext); +// +// return $container; +//} +// +///** +//* Create installer container +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object +//*/ +//function phpbb_create_install_container($phpbb_root_path, $php_ext) +//{ +// $other_config_path = $phpbb_root_path . 'install/update/new/config/'; +// $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; +// +// $core = new \phpbb\di\extension\core($config_path); +// $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); +// +// $container->setParameter('core.root_path', $phpbb_root_path); +// $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); +// $container->setParameter('core.php_ext', $php_ext); +// $container->setParameter('core.table_prefix', ''); +// +// $container->register('dbal.conn')->setSynthetic(true); +// +// $container->setAlias('cache.driver', 'cache.driver.install'); +// +// $container->compile(); +// +// return $container; +//} +// +///** +//* Create updater container +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @param array $config_path Path to config directory +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) +//{ +// $config_file = $phpbb_root_path . 'config.' . $php_ext; +// return phpbb_create_compiled_container( +// $config_file, +// array( +// new phpbb\di\extension\config($config_file), +// new phpbb\di\extension\core($config_path), +// ), +// array( +// new phpbb\di\pass\collection_pass(), +// new phpbb\di\pass\kernel_pass(), +// ), +// $phpbb_root_path, +// $php_ext +// ); +//} +// +///** +//* Create a compiled ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// // Create the final container to be compiled and cached +// $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); +// +// // Compile the container +// foreach ($passes as $pass) +// { +// $container->addCompilerPass($pass); +// } +// $container->compile(); +// +// return $container; +//} +// +///** +//* Create a compiled and dumped ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// // Check for our cached container; if it exists, use it +// $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); +// if (file_exists($container_filename)) +// { +// require($container_filename); +// return new phpbb_cache_container(); +// } +// +// $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); +// +// // Lastly, we create our cached container class +// $dumper = new PhpDumper($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); +// +// return $container; +//} +// +///** +//* Create an environment-specific ContainerBuilder object +//* +//* If debug is enabled, the container is re-compiled every time. +//* This ensures that the latest changes will always be reflected +//* during development. +//* +//* Otherwise it will get the existing dumped container and use +//* that one instead. +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// $container_factory = defined('DEBUG_CONTAINER') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; +// return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); +//} +// +///** +//* Create a default ContainerBuilder object +//* +//* Contains the default configuration of the phpBB container. +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_default_container($phpbb_root_path, $php_ext) +//{ +// $config_file = $phpbb_root_path . 'config.' . $php_ext; +// $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path); +// +// return phpbb_create_dumped_container_unless_debug( +// $config_file, +// array( +// new \phpbb\di\extension\config($config_file), +// new \phpbb\di\extension\core($phpbb_root_path . 'config'), +// new \phpbb\di\extension\ext($installed_exts), +// ), +// array( +// new \phpbb\di\pass\collection_pass(), +// new \phpbb\di\pass\kernel_pass(), +// ), +// $phpbb_root_path, +// $php_ext +// ); +//} +// +///** +//* Get the filename under which the dumped container will be stored. +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return Path for dumped container +//*/ +//function phpbb_container_filename($phpbb_root_path, $php_ext) +//{ +// $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); +// return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; +//} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 63e4e8f4ac1..481f52de65a 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -56,8 +56,15 @@ function phpbb_end_update($cache, $config) } require($phpbb_root_path . 'includes/startup.' . $phpEx); +require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); + +// Setup class loader first +$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); +$phpbb_class_loader->register(); + +$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +extract($phpbb_config_php_handler->get_all()); -include($phpbb_root_path . 'config.' . $phpEx); if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { die("Please read: INSTALL.html before attempting to update."); @@ -68,11 +75,8 @@ function phpbb_end_update($cache, $config) $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include files -require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); -require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -82,26 +86,12 @@ function phpbb_end_update($cache, $config) // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -// Setup class loader first -$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); -$phpbb_class_loader->register(); - // Set up container (must be done here because extensions table may not exist) -$container_extensions = array( - new \phpbb\di\extension\config($phpbb_root_path . 'config.' . $phpEx), - new \phpbb\di\extension\core($phpbb_root_path . 'config/'), -); -$container_passes = array( - new \phpbb\di\pass\collection_pass(), -); -$phpbb_container = phpbb_create_container($container_extensions, $phpbb_root_path, $phpEx); - -// Compile the container -foreach ($container_passes as $pass) -{ - $phpbb_container->addCompilerPass($pass); -} -$phpbb_container->compile(); +$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_factory->set_use_extensions(false); +$phpbb_container_factory->set_use_kernel_pass(false); +$phpbb_container_factory->set_dump_container(false); +$phpbb_container = $phpbb_container_factory->get_container(); // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index d5020888977..31a84662fa1 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 @@ 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; } /** @@ -87,12 +106,12 @@ protected function load_config_file() { 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 dd348d8eee8..548bbf153fe 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 @@ public function get_container() 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 @@ public function set_use_extensions($use_extensions) * * @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. * From ef1346c931a2ddd095d5dbf296cb598dca6edfe8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:27:55 +0200 Subject: [PATCH 12/34] [ticket/12775] Update phpBB/install/index.php PHPBB3-12775 --- phpBB/config/services.yml | 3 --- phpBB/install/index.php | 24 +++++++++++++++++++++++- phpBB/phpbb/di/container_factory.php | 25 ++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 09dfc2fba2e..ec56ae8e9ac 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -39,9 +39,6 @@ services: cache.driver: class: %cache.driver.class% - cache.driver.install: - class: phpbb\cache\driver\file - class_loader: class: phpbb\class_loader arguments: diff --git a/phpBB/install/index.php b/phpBB/install/index.php index c8a745825a5..e72a3bca9c0 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -120,7 +120,29 @@ function phpbb_include_updated($path, $optional = false) $phpbb_class_loader_ext->register(); // Set up container -$phpbb_container = phpbb_create_install_container($phpbb_root_path, $phpEx); +$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_factory->set_use_extensions(false); +$phpbb_container_factory->set_dump_container(false); +$phpbb_container_factory->set_use_custom_pass(false); +$phpbb_container_factory->set_inject_config(false); +$phpbb_container_factory->set_compile_container(false); + +$other_config_path = $phpbb_root_path . 'install/update/new/config/'; +$config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; +$phpbb_container_factory->set_config_path($config_path); + +$phpbb_container_factory->set_custom_parameters(array( + 'core.root_path' => $phpbb_root_path, + 'core.adm_relative_path' => $phpbb_adm_relative_path, + 'core.php_ext' => $phpEx, + 'core.table_prefix' => '', + 'cache.driver.class' => 'phpbb\cache\driver\file', +)); + +$phpbb_container = $phpbb_container_factory->get_container(); +$phpbb_container->register('dbal.conn')->setSynthetic(true); +$phpbb_container->compile(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index 548bbf153fe..a83c79f5170 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 @@ public function get_container() $this->inject_custom_parameters(); - $this->container->compile(); + if ($this->compile_container) + { + $this->container->compile(); + } if ($this->dump_container && defined('DEBUG')) { @@ -227,6 +236,16 @@ 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 * From 20912d7af2428200fc02fe87b55071240b2a9315 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:28:58 +0200 Subject: [PATCH 13/34] [ticket/12775] Skip the tests related to the container PHPBB3-12775 --- tests/di/create_container_test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 8bf9f636fac..5983b244fd7 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -20,6 +20,7 @@ class phpbb_di_container_test extends phpbb_test_case { public function test_phpbb_create_container() { + $this->markTestSkipped(); $phpbb_root_path = __DIR__ . '/../../phpBB/'; $extensions = array( new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), @@ -32,6 +33,7 @@ public function test_phpbb_create_container() public function test_phpbb_create_install_container() { + $this->markTestSkipped(); $phpbb_root_path = __DIR__ . '/../../phpBB/'; $extensions = array( new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), @@ -45,6 +47,7 @@ public function test_phpbb_create_install_container() public function test_phpbb_create_compiled_container() { + $this->markTestSkipped(); $phpbb_root_path = __DIR__ . '/../../phpBB/'; $config_file = __DIR__ . '/fixtures/config.php'; $extensions = array( From cefffe07771162da3dba1bbc7febc611b508e7aa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:35:53 +0200 Subject: [PATCH 14/34] [ticket/12775] Load the config file before constants.php PHPBB3-12775 --- phpBB/bin/phpbbcli.php | 14 ++++++++------ phpBB/download/file.php | 16 +++++++--------- phpBB/install/database_update.php | 1 - 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index e6b9e3ac8d3..8baeae5b4e6 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -22,20 +22,22 @@ $phpbb_root_path = __DIR__ . '/../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require($phpbb_root_path . 'includes/startup.' . $phpEx); -require($phpbb_root_path . 'includes/constants.' . $phpEx); -require($phpbb_root_path . 'includes/functions.' . $phpEx); -require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); -require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); -$phpbb_class_loader_ext->register(); $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); extract($phpbb_config_php_handler->get_all()); +require($phpbb_root_path . 'includes/constants.' . $phpEx); +require($phpbb_root_path . 'includes/functions.' . $phpEx); +require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + +$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); +$phpbb_class_loader_ext->register(); + $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); $phpbb_container_factory->set_use_extensions(false); $phpbb_container_factory->set_dump_container(false); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 636a73a95f2..84c1c51c1ce 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -39,29 +39,27 @@ { require($phpbb_root_path . 'includes/startup.' . $phpEx); + require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); + $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); + $phpbb_class_loader->register(); + + $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); + extract($phpbb_config_php_handler->get_all()); + if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { exit; } - require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Setup class loader first - $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); - $phpbb_class_loader->register(); $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); - phpbb_load_extensions_autoloaders($phpbb_root_path); - - $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); - extract($phpbb_config_php_handler->get_all()); - // Set up container $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_factory->get_container(); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 481f52de65a..869d650b7c8 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -78,7 +78,6 @@ function phpbb_end_update($cache, $config) require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); -require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); From 91ca12f20ec0901a02222a83abd18df7efa84d81 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:48:27 +0200 Subject: [PATCH 15/34] [ticket/12775] Update container and config in install/ PHPBB3-12775 --- phpBB/install/install_convert.php | 25 +++++++++++++++++-------- phpBB/install/install_install.php | 5 +++-- phpBB/install/install_update.php | 15 ++++++++------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 6109f5e28b0..9e983d7f405 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -107,7 +107,7 @@ function install_convert(&$p_master) function main($mode, $sub) { global $lang, $template, $phpbb_root_path, $phpEx, $cache, $config, $language, $table_prefix; - global $convert, $request, $phpbb_container; + global $convert, $request, $phpbb_container, $phpbb_config_php_handler; $this->tpl_name = 'install_convert'; $this->mode = $mode; @@ -127,7 +127,8 @@ function main($mode, $sub) // Enable super globals to prevent issues with the new \phpbb\request\request object $request->enable_super_globals(); // Create a normal container now - $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); + $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_factory->get_container(); // Create cache $cache = $phpbb_container->get('cache'); @@ -135,7 +136,9 @@ function main($mode, $sub) switch ($sub) { case 'intro': - require($phpbb_root_path . 'config.' . $phpEx); + $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_handler->get_all()); + require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -224,7 +227,9 @@ function main($mode, $sub) // This is for making sure the session get not screwed due to the 3.0.x users table being completely new. $cache->purge(); - require($phpbb_root_path . 'config.' . $phpEx); + $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_handler->get_all()); + require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -370,9 +375,11 @@ function list_convertors($sub) */ function get_convert_settings($sub) { - global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache; + global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache, $phpbb_config_php_handler; + + $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_handler->get_all()); - require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -614,9 +621,11 @@ function convert_data($sub) { global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth; global $convert, $convert_row, $message_parser, $skip_rows, $language; - global $request; + global $request, $phpbb_config_php_handler; + + $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_handler->get_all()); - require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 43fd6eaf075..d052297d81e 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -51,7 +51,7 @@ function install_install(&$p_master) function main($mode, $sub) { global $lang, $template, $language, $phpbb_root_path, $phpEx; - global $phpbb_container, $cache, $phpbb_log, $request; + global $phpbb_container, $cache, $phpbb_log, $request, $phpbb_config_php_handler; switch ($sub) { @@ -104,7 +104,8 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); + $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_factory->get_container(); // Sets the global variables $cache = $phpbb_container->get('cache'); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index c6f771a7d54..943b89f2d79 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -66,7 +66,9 @@ function install_update(&$p_master) function main($mode, $sub) { global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; - global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container; + global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container, $phpbb_config_php_handler; + + extract($phpbb_config_php_handler->get_all()); // We must enable super globals, otherwise creating a new instance of the request class, // using the new container with a dbal connection will fail with the following PHP Notice: @@ -74,14 +76,14 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now + $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_factory->set_dump_container(false); + $phpbb_container_factory->set_use_extensions(false); if (file_exists($phpbb_root_path . 'install/update/new/config')) { - $phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, $phpbb_root_path . 'install/update/new/config'); - } - else - { - $phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, $phpbb_root_path . 'config'); + $phpbb_container_factory->set_config_path($phpbb_root_path . 'install/update/new/config'); } + $phpbb_container = $phpbb_container_factory->get_container(); // Writes into global $cache $cache = $phpbb_container->get('cache'); @@ -93,7 +95,6 @@ function main($mode, $sub) $this->new_location = $phpbb_root_path . 'install/update/new/'; // Init DB - require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); // Special options for conflicts/modified files From c87f44c6692c55adb3ce5bc5b7bca8da7b1357ab Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 23:29:43 +0200 Subject: [PATCH 16/34] [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(-) diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index 31a84662fa1..81910234374 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -108,11 +108,11 @@ protected function load_config_file() { 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; } From 1d966fbc86db47c3518b35de849cad3a1f295e71 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 28 Jun 2014 01:36:59 +0200 Subject: [PATCH 17/34] [ticket/12775] Add tests for the container factory PHPBB3-12775 --- phpBB/includes/functions_container.php | 291 ------------------ phpBB/phpbb/di/container_factory.php | 2 +- tests/di/create_container_test.php | 148 +++++++-- tests/di/fixtures/config/services.yml | 9 + .../ext/vendor/available/config/services.yml | 2 + .../ext/vendor/disabled/config/services.yml | 2 + .../ext/vendor/enabled/config/services.yml | 2 + tests/di/fixtures/other_config/services.yml | 9 + tests/mock/container_factory.php | 20 ++ 9 files changed, 165 insertions(+), 320 deletions(-) delete mode 100644 phpBB/includes/functions_container.php create mode 100644 tests/di/fixtures/config/services.yml create mode 100644 tests/di/fixtures/ext/vendor/available/config/services.yml create mode 100644 tests/di/fixtures/ext/vendor/disabled/config/services.yml create mode 100644 tests/di/fixtures/ext/vendor/enabled/config/services.yml create mode 100644 tests/di/fixtures/other_config/services.yml create mode 100644 tests/mock/container_factory.php diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php deleted file mode 100644 index 96086a59ed3..00000000000 --- a/phpBB/includes/functions_container.php +++ /dev/null @@ -1,291 +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. -//* -//*/ -// -//use Symfony\Component\Config\FileLocator; -//use Symfony\Component\DependencyInjection\ContainerBuilder; -//use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -//use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -// -///** -//* @ignore -//*/ -//if (!defined('IN_PHPBB')) -//{ -// exit; -//} -// -///** -//* Get DB connection from config.php. -//* -//* Used to bootstrap the container. -//* -//* @param string $config_file -//* @return \phpbb\db\driver\driver_interface -//*/ -//function phpbb_bootstrap_db_connection($config_file) -//{ -// require($config_file); -// $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); -// -// $db = new $dbal_driver_class(); -// $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); -// -// return $db; -//} -// -///** -//* Get table prefix from config.php. -//* -//* Used to bootstrap the container. -//* -//* @param string $config_file -//* @return string table prefix -//*/ -//function phpbb_bootstrap_table_prefix($config_file) -//{ -// require($config_file); -// return $table_prefix; -//} -// -///** -//* Get enabled extensions. -//* -//* Used to bootstrap the container. -//* -//* @param string $config_file -//* @param string $phpbb_root_path -//* @return array enabled extensions -//*/ -//function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path) -//{ -// $db = phpbb_bootstrap_db_connection($config_file); -// $table_prefix = phpbb_bootstrap_table_prefix($config_file); -// $extension_table = $table_prefix.'ext'; -// -// $sql = 'SELECT * -// FROM ' . $extension_table . ' -// WHERE ext_active = 1'; -// -// $result = $db->sql_query($sql); -// $rows = $db->sql_fetchrowset($result); -// $db->sql_freeresult($result); -// -// $exts = array(); -// foreach ($rows as $row) -// { -// $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; -// } -// -// return $exts; -//} -// -///** -//* Create the ContainerBuilder object -//* -//* @param array $extensions Array of Container extension objects -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return ContainerBuilder object -//*/ -//function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) -//{ -// $container = new ContainerBuilder(); -// -// foreach ($extensions as $extension) -// { -// $container->registerExtension($extension); -// $container->loadFromExtension($extension->getAlias()); -// } -// -// $container->setParameter('core.root_path', $phpbb_root_path); -// $container->setParameter('core.php_ext', $php_ext); -// -// return $container; -//} -// -///** -//* Create installer container -//* -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return ContainerBuilder object -//*/ -//function phpbb_create_install_container($phpbb_root_path, $php_ext) -//{ -// $other_config_path = $phpbb_root_path . 'install/update/new/config/'; -// $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; -// -// $core = new \phpbb\di\extension\core($config_path); -// $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); -// -// $container->setParameter('core.root_path', $phpbb_root_path); -// $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); -// $container->setParameter('core.php_ext', $php_ext); -// $container->setParameter('core.table_prefix', ''); -// -// $container->register('dbal.conn')->setSynthetic(true); -// -// $container->setAlias('cache.driver', 'cache.driver.install'); -// -// $container->compile(); -// -// return $container; -//} -// -///** -//* Create updater container -//* -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @param array $config_path Path to config directory -//* @return ContainerBuilder object (compiled) -//*/ -//function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) -//{ -// $config_file = $phpbb_root_path . 'config.' . $php_ext; -// return phpbb_create_compiled_container( -// $config_file, -// array( -// new phpbb\di\extension\config($config_file), -// new phpbb\di\extension\core($config_path), -// ), -// array( -// new phpbb\di\pass\collection_pass(), -// new phpbb\di\pass\kernel_pass(), -// ), -// $phpbb_root_path, -// $php_ext -// ); -//} -// -///** -//* Create a compiled ContainerBuilder object -//* -//* @param array $extensions Array of Container extension objects -//* @param array $passes Array of Compiler Pass objects -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return ContainerBuilder object (compiled) -//*/ -//function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -//{ -// // Create the final container to be compiled and cached -// $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); -// -// // Compile the container -// foreach ($passes as $pass) -// { -// $container->addCompilerPass($pass); -// } -// $container->compile(); -// -// return $container; -//} -// -///** -//* Create a compiled and dumped ContainerBuilder object -//* -//* @param array $extensions Array of Container extension objects -//* @param array $passes Array of Compiler Pass objects -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return ContainerBuilder object (compiled) -//*/ -//function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -//{ -// // Check for our cached container; if it exists, use it -// $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); -// if (file_exists($container_filename)) -// { -// require($container_filename); -// return new phpbb_cache_container(); -// } -// -// $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); -// -// // Lastly, we create our cached container class -// $dumper = new PhpDumper($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); -// -// return $container; -//} -// -///** -//* Create an environment-specific ContainerBuilder object -//* -//* If debug is enabled, the container is re-compiled every time. -//* This ensures that the latest changes will always be reflected -//* during development. -//* -//* Otherwise it will get the existing dumped container and use -//* that one instead. -//* -//* @param array $extensions Array of Container extension objects -//* @param array $passes Array of Compiler Pass objects -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return ContainerBuilder object (compiled) -//*/ -//function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -//{ -// $container_factory = defined('DEBUG_CONTAINER') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; -// return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); -//} -// -///** -//* Create a default ContainerBuilder object -//* -//* Contains the default configuration of the phpBB container. -//* -//* @param array $extensions Array of Container extension objects -//* @param array $passes Array of Compiler Pass objects -//* @return ContainerBuilder object (compiled) -//*/ -//function phpbb_create_default_container($phpbb_root_path, $php_ext) -//{ -// $config_file = $phpbb_root_path . 'config.' . $php_ext; -// $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path); -// -// return phpbb_create_dumped_container_unless_debug( -// $config_file, -// array( -// new \phpbb\di\extension\config($config_file), -// new \phpbb\di\extension\core($phpbb_root_path . 'config'), -// new \phpbb\di\extension\ext($installed_exts), -// ), -// array( -// new \phpbb\di\pass\collection_pass(), -// new \phpbb\di\pass\kernel_pass(), -// ), -// $phpbb_root_path, -// $php_ext -// ); -//} -// -///** -//* Get the filename under which the dumped container will be stored. -//* -//* @param string $phpbb_root_path Root path -//* @param string $php_ext PHP Extension -//* @return Path for dumped container -//*/ -//function phpbb_container_filename($phpbb_root_path, $php_ext) -//{ -// $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); -// return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; -//} diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index a83c79f5170..426c411e07e 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -170,7 +170,7 @@ public function get_container() $this->container->compile(); } - if ($this->dump_container && defined('DEBUG')) + if ($this->dump_container && !defined('DEBUG')) { $this->dump_container($container_filename); } diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 5983b244fd7..d41f1af5ae1 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -14,50 +14,135 @@ namespace { require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; - class phpbb_di_container_test extends phpbb_test_case + class phpbb_di_container_test extends \phpbb_test_case { - public function test_phpbb_create_container() + protected $config_php; + + /** + * @var \phpbb\di\container_factory + */ + protected $factory; + protected $phpbb_root_path; + protected $filename; + + public function setUp() { - $this->markTestSkipped(); - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $extensions = array( - new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), - new \phpbb\di\extension\core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_container($extensions, $phpbb_root_path, 'php'); + $this->phpbb_root_path = dirname(__FILE__) . '/'; + $this->config_php = new \phpbb\config_php($this->phpbb_root_path . 'fixtures/', 'php'); + $this->factory = new phpbb_mock_container_factory($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); + + $this->filename = $this->phpbb_root_path . '../tmp/cache/container.php'; + if (is_file($this->filename)) + { + unlink($this->filename); + } + + parent::setUp(); + } + public function test_default_container() + { + $container = $this->factory->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + + // Checks the core services + $this->assertTrue($container->hasParameter('core')); + + // Checks compile_container + $this->assertTrue($container->isFrozen()); + + // Checks inject_config + $this->assertTrue($container->hasParameter('dbal.dbhost')); + + // Checks use_extensions + $this->assertTrue($container->hasParameter('enabled')); + $this->assertFalse($container->hasParameter('disabled')); + $this->assertFalse($container->hasParameter('available')); + + // Checks set_custom_parameters + $this->assertTrue($container->hasParameter('core.root_path')); + + // Checks dump_container + $this->assertTrue(is_file($this->filename)); + + // Checks the construction of a dumped container + $container = $this->factory->get_container(); + $this->assertInstanceOf('phpbb_cache_container', $container); + $this->assertFalse($container->isFrozen()); + $container->getParameterBag(); // needed, otherwise the container is not marked as frozen + $this->assertTrue($container->isFrozen()); } - public function test_phpbb_create_install_container() + public function test_dump_container() { - $this->markTestSkipped(); - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $extensions = array( - new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), - new \phpbb\di\extension\core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_install_container($phpbb_root_path, 'php'); + $this->factory->set_dump_container(false); + $container = $this->factory->get_container(); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + // Checks dump_container + $this->assertFalse(is_file($this->filename)); + + // Checks the construction of a dumped container + $container = $this->factory->get_container(); + $this->assertNotInstanceOf('phpbb_cache_container', $container); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->isFrozen()); } - public function test_phpbb_create_compiled_container() + public function test_use_extensions() { - $this->markTestSkipped(); - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $config_file = __DIR__ . '/fixtures/config.php'; - $extensions = array( - new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), - new \phpbb\di\extension\core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php'); + $this->factory->set_use_extensions(false); + $container = $this->factory->get_container(); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + + // Checks the core services + $this->assertTrue($container->hasParameter('core')); + + // Checks use_extensions + $this->assertFalse($container->hasParameter('enabled')); + $this->assertFalse($container->hasParameter('disabled')); + $this->assertFalse($container->hasParameter('available')); + } + public function test_compile_container() + { + $this->factory->set_compile_container(false); + $container = $this->factory->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); - $this->assertTrue($container->isFrozen()); + + // Checks compile_container + $this->assertFalse($container->isFrozen()); + } + + public function test_inject_config() + { + $this->factory->set_inject_config(false); + $container = $this->factory->get_container(); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + + // Checks inject_config + $this->assertFalse($container->hasParameter('dbal.dbhost')); + } + + public function test_set_config_path() + { + $this->factory->set_config_path($this->phpbb_root_path . 'fixtures/other_config/'); + $container = $this->factory->get_container(); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + + $this->assertTrue($container->hasParameter('other_config')); + $this->assertFalse($container->hasParameter('core')); + } + + public function test_set_custom_parameters() + { + $this->factory->set_custom_parameters(array('my_parameter' => true)); + $container = $this->factory->get_container(); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + + $this->assertTrue($container->hasParameter('my_parameter')); + $this->assertFalse($container->hasParameter('core.root_path')); } } } @@ -105,5 +190,12 @@ function sql_escape($msg) function sql_like_expression($expression) { } + + function sql_fetchrowset($query_id = false) + { + return array( + array('ext_name' => 'vendor/enabled'), + ); + } } } diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml new file mode 100644 index 00000000000..71bc14f69a1 --- /dev/null +++ b/tests/di/fixtures/config/services.yml @@ -0,0 +1,9 @@ +parameters: + core: true + +services: + dispatcher: + class: phpbb\db\driver\container_mock + + config.php: + synthetic: true diff --git a/tests/di/fixtures/ext/vendor/available/config/services.yml b/tests/di/fixtures/ext/vendor/available/config/services.yml new file mode 100644 index 00000000000..2ced431f5af --- /dev/null +++ b/tests/di/fixtures/ext/vendor/available/config/services.yml @@ -0,0 +1,2 @@ +parameters: + available: true diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/services.yml new file mode 100644 index 00000000000..31ada384bf3 --- /dev/null +++ b/tests/di/fixtures/ext/vendor/disabled/config/services.yml @@ -0,0 +1,2 @@ +parameters: + disabled: true diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/services.yml new file mode 100644 index 00000000000..88a7919ed1a --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled/config/services.yml @@ -0,0 +1,2 @@ +parameters: + enabled: true diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml new file mode 100644 index 00000000000..5974d3b7585 --- /dev/null +++ b/tests/di/fixtures/other_config/services.yml @@ -0,0 +1,9 @@ +parameters: + other_config: true + +services: + dispatcher: + class: phpbb\db\driver\container_mock + + config.php: + synthetic: true diff --git a/tests/mock/container_factory.php b/tests/mock/container_factory.php new file mode 100644 index 00000000000..8b1720d027d --- /dev/null +++ b/tests/mock/container_factory.php @@ -0,0 +1,20 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_mock_container_factory extends \phpbb\di\container_factory +{ + protected function get_container_filename() + { + return $this->phpbb_root_path . '../../tmp/cache/container.' . $this->php_ext; + } +} From afffec81847c3414c7e33a3b83cd750853aafddd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 28 Jun 2014 01:46:48 +0200 Subject: [PATCH 18/34] [ticket/12775] Add tests for \phpbb\config_php PHPBB3-12775 --- tests/config_php_test.php | 30 ++++++++++++++++++++++++++++++ tests/fixtures/config.php | 3 +++ tests/fixtures/config_other.php | 3 +++ 3 files changed, 36 insertions(+) create mode 100644 tests/config_php_test.php create mode 100644 tests/fixtures/config.php create mode 100644 tests/fixtures/config_other.php diff --git a/tests/config_php_test.php b/tests/config_php_test.php new file mode 100644 index 00000000000..6e2b4c2ac11 --- /dev/null +++ b/tests/config_php_test.php @@ -0,0 +1,30 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_config_php_test extends phpbb_test_case +{ + public function test_default() + { + $config_php = new \phpbb\config_php(dirname( __FILE__ ) . '/fixtures/', 'php'); + $this->assertSame('bar', $config_php->get('foo')); + $this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all()); + } + + public function test_set_config_file() + { + $config_php = new \phpbb\config_php(dirname( __FILE__ ) . '/fixtures/', 'php'); + $config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php'); + $this->assertSame('foo', $config_php->get('bar')); + $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all()); + } +} diff --git a/tests/fixtures/config.php b/tests/fixtures/config.php new file mode 100644 index 00000000000..ae9e8c22de6 --- /dev/null +++ b/tests/fixtures/config.php @@ -0,0 +1,3 @@ + Date: Sat, 28 Jun 2014 02:02:27 +0200 Subject: [PATCH 19/34] [ticket/12775] Fix unit tests PHPBB3-12775 --- tests/di/create_container_test.php | 2 +- tests/mock/container_factory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index d41f1af5ae1..a71da1734da 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -32,7 +32,7 @@ public function setUp() $this->config_php = new \phpbb\config_php($this->phpbb_root_path . 'fixtures/', 'php'); $this->factory = new phpbb_mock_container_factory($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); - $this->filename = $this->phpbb_root_path . '../tmp/cache/container.php'; + $this->filename = $this->phpbb_root_path . '../tmp/container.php'; if (is_file($this->filename)) { unlink($this->filename); diff --git a/tests/mock/container_factory.php b/tests/mock/container_factory.php index 8b1720d027d..d547c8dd68a 100644 --- a/tests/mock/container_factory.php +++ b/tests/mock/container_factory.php @@ -15,6 +15,6 @@ class phpbb_mock_container_factory extends \phpbb\di\container_factory { protected function get_container_filename() { - return $this->phpbb_root_path . '../../tmp/cache/container.' . $this->php_ext; + return $this->phpbb_root_path . '../../tmp/container.' . $this->php_ext; } } From 11ff91c87d683d1a76ef1d5c0a9fb0c79d74cd15 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 28 Jun 2014 02:08:29 +0200 Subject: [PATCH 20/34] [ticket/12775] Remove the last include of functions_container PHPBB3-12775 --- phpBB/install/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index e72a3bca9c0..f350a329d20 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -102,7 +102,6 @@ function phpbb_include_updated($path, $optional = false) phpbb_require_updated('phpbb/class_loader.' . $phpEx); phpbb_require_updated('includes/functions.' . $phpEx); -phpbb_require_updated('includes/functions_container.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); From 40937e21c58399a847d04f23423622b0e1894446 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:29:08 +0200 Subject: [PATCH 21/34] [ticket/12775] Renamed to \phpbb\di\container_builder PHPBB3-12775 --- phpBB/bin/phpbbcli.php | 8 ++--- phpBB/common.php | 4 +-- phpBB/download/file.php | 4 +-- phpBB/install/database_update.php | 10 +++--- phpBB/install/index.php | 18 +++++----- phpBB/install/install_convert.php | 4 +-- phpBB/install/install_install.php | 4 +-- phpBB/install/install_update.php | 10 +++--- ...iner_factory.php => container_builder.php} | 0 tests/di/create_container_test.php | 34 +++++++++---------- ...ory.php => phpbb_di_container_builder.php} | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) rename phpBB/phpbb/di/{container_factory.php => container_builder.php} (100%) rename tests/mock/{container_factory.php => phpbb_di_container_builder.php} (83%) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 8baeae5b4e6..9e9f1e27e67 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -38,11 +38,11 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); -$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); -$phpbb_container_factory->set_use_extensions(false); -$phpbb_container_factory->set_dump_container(false); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder->set_use_extensions(false); +$phpbb_container_builder->set_dump_container(false); -$phpbb_container = $phpbb_container_factory->get_container(); +$phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->get('request')->enable_super_globals(); require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx); diff --git a/phpBB/common.php b/phpBB/common.php index 8c9e5b60239..b5aaedd6e0b 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -95,8 +95,8 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); -$phpbb_container = $phpbb_container_factory->get_container(); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 84c1c51c1ce..5507464209b 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -61,8 +61,8 @@ $phpbb_class_loader_ext->register(); // Set up container - $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); - $phpbb_container = $phpbb_container_factory->get_container(); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 869d650b7c8..392bb2ad8ce 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -86,11 +86,11 @@ function phpbb_end_update($cache, $config) set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); // Set up container (must be done here because extensions table may not exist) -$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); -$phpbb_container_factory->set_use_extensions(false); -$phpbb_container_factory->set_use_kernel_pass(false); -$phpbb_container_factory->set_dump_container(false); -$phpbb_container = $phpbb_container_factory->get_container(); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder->set_use_extensions(false); +$phpbb_container_builder->set_use_kernel_pass(false); +$phpbb_container_builder->set_dump_container(false); +$phpbb_container = $phpbb_container_builder->get_container(); // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index f350a329d20..1c81d552a2f 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -120,18 +120,18 @@ function phpbb_include_updated($path, $optional = false) // Set up container $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); -$phpbb_container_factory->set_use_extensions(false); -$phpbb_container_factory->set_dump_container(false); -$phpbb_container_factory->set_use_custom_pass(false); -$phpbb_container_factory->set_inject_config(false); -$phpbb_container_factory->set_compile_container(false); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder->set_use_extensions(false); +$phpbb_container_builder->set_dump_container(false); +$phpbb_container_builder->set_use_custom_pass(false); +$phpbb_container_builder->set_inject_config(false); +$phpbb_container_builder->set_compile_container(false); $other_config_path = $phpbb_root_path . 'install/update/new/config/'; $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; -$phpbb_container_factory->set_config_path($config_path); +$phpbb_container_builder->set_config_path($config_path); -$phpbb_container_factory->set_custom_parameters(array( +$phpbb_container_builder->set_custom_parameters(array( 'core.root_path' => $phpbb_root_path, 'core.adm_relative_path' => $phpbb_adm_relative_path, 'core.php_ext' => $phpEx, @@ -139,7 +139,7 @@ function phpbb_include_updated($path, $optional = false) 'cache.driver.class' => 'phpbb\cache\driver\file', )); -$phpbb_container = $phpbb_container_factory->get_container(); +$phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->register('dbal.conn')->setSynthetic(true); $phpbb_container->compile(); diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 9e983d7f405..8f77d0be9a9 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -127,8 +127,8 @@ function main($mode, $sub) // Enable super globals to prevent issues with the new \phpbb\request\request object $request->enable_super_globals(); // Create a normal container now - $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); - $phpbb_container = $phpbb_container_factory->get_container(); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_builder->get_container(); // Create cache $cache = $phpbb_container->get('cache'); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index d052297d81e..1abe19e5b52 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -104,8 +104,8 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); - $phpbb_container = $phpbb_container_factory->get_container(); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_builder->get_container(); // Sets the global variables $cache = $phpbb_container->get('cache'); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 943b89f2d79..5474ae71bcc 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -76,14 +76,14 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); - $phpbb_container_factory->set_dump_container(false); - $phpbb_container_factory->set_use_extensions(false); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_builder->set_dump_container(false); + $phpbb_container_builder->set_use_extensions(false); if (file_exists($phpbb_root_path . 'install/update/new/config')) { - $phpbb_container_factory->set_config_path($phpbb_root_path . 'install/update/new/config'); + $phpbb_container_builder->set_config_path($phpbb_root_path . 'install/update/new/config'); } - $phpbb_container = $phpbb_container_factory->get_container(); + $phpbb_container = $phpbb_container_builder->get_container(); // Writes into global $cache $cache = $phpbb_container->get('cache'); diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_builder.php similarity index 100% rename from phpBB/phpbb/di/container_factory.php rename to phpBB/phpbb/di/container_builder.php diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index a71da1734da..57500c2ad25 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -22,7 +22,7 @@ class phpbb_di_container_test extends \phpbb_test_case /** * @var \phpbb\di\container_factory */ - protected $factory; + protected $builder; protected $phpbb_root_path; protected $filename; @@ -30,7 +30,7 @@ public function setUp() { $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->config_php = new \phpbb\config_php($this->phpbb_root_path . 'fixtures/', 'php'); - $this->factory = new phpbb_mock_container_factory($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); + $this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); $this->filename = $this->phpbb_root_path . '../tmp/container.php'; if (is_file($this->filename)) @@ -43,7 +43,7 @@ public function setUp() public function test_default_container() { - $container = $this->factory->get_container(); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); // Checks the core services @@ -67,7 +67,7 @@ public function test_default_container() $this->assertTrue(is_file($this->filename)); // Checks the construction of a dumped container - $container = $this->factory->get_container(); + $container = $this->builder->get_container(); $this->assertInstanceOf('phpbb_cache_container', $container); $this->assertFalse($container->isFrozen()); $container->getParameterBag(); // needed, otherwise the container is not marked as frozen @@ -76,15 +76,15 @@ public function test_default_container() public function test_dump_container() { - $this->factory->set_dump_container(false); - $container = $this->factory->get_container(); + $this->builder->set_dump_container(false); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); // Checks dump_container $this->assertFalse(is_file($this->filename)); // Checks the construction of a dumped container - $container = $this->factory->get_container(); + $container = $this->builder->get_container(); $this->assertNotInstanceOf('phpbb_cache_container', $container); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->isFrozen()); @@ -92,8 +92,8 @@ public function test_dump_container() public function test_use_extensions() { - $this->factory->set_use_extensions(false); - $container = $this->factory->get_container(); + $this->builder->set_use_extensions(false); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); // Checks the core services @@ -107,8 +107,8 @@ public function test_use_extensions() public function test_compile_container() { - $this->factory->set_compile_container(false); - $container = $this->factory->get_container(); + $this->builder->set_compile_container(false); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); // Checks compile_container @@ -117,8 +117,8 @@ public function test_compile_container() public function test_inject_config() { - $this->factory->set_inject_config(false); - $container = $this->factory->get_container(); + $this->builder->set_inject_config(false); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); // Checks inject_config @@ -127,8 +127,8 @@ public function test_inject_config() public function test_set_config_path() { - $this->factory->set_config_path($this->phpbb_root_path . 'fixtures/other_config/'); - $container = $this->factory->get_container(); + $this->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/'); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->hasParameter('other_config')); @@ -137,8 +137,8 @@ public function test_set_config_path() public function test_set_custom_parameters() { - $this->factory->set_custom_parameters(array('my_parameter' => true)); - $container = $this->factory->get_container(); + $this->builder->set_custom_parameters(array('my_parameter' => true)); + $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->hasParameter('my_parameter')); diff --git a/tests/mock/container_factory.php b/tests/mock/phpbb_di_container_builder.php similarity index 83% rename from tests/mock/container_factory.php rename to tests/mock/phpbb_di_container_builder.php index d547c8dd68a..235fa32b267 100644 --- a/tests/mock/container_factory.php +++ b/tests/mock/phpbb_di_container_builder.php @@ -11,7 +11,7 @@ * */ -class phpbb_mock_container_factory extends \phpbb\di\container_factory +class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_factory { protected function get_container_filename() { From 2db160ff87fa42ca6c47e580de9bc9d7e5cced49 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:33:31 +0200 Subject: [PATCH 22/34] [ticket/12775] Rename config_php to config_php_file PHPBB3-12775 --- phpBB/bin/phpbbcli.php | 6 ++--- phpBB/common.php | 6 ++--- phpBB/download/file.php | 6 ++--- phpBB/install/database_update.php | 6 ++--- phpBB/install/index.php | 4 ++-- phpBB/install/install_convert.php | 24 +++++++++---------- phpBB/install/install_install.php | 4 ++-- phpBB/install/install_update.php | 6 ++--- .../{config_php.php => config_php_file.php} | 2 +- phpBB/phpbb/di/container_builder.php | 4 ++-- phpBB/phpbb/di/extension/config.php | 2 +- ..._php_test.php => config_php_file_test.php} | 6 ++--- tests/di/create_container_test.php | 2 +- 13 files changed, 39 insertions(+), 39 deletions(-) rename phpBB/phpbb/{config_php.php => config_php_file.php} (99%) rename tests/{config_php_test.php => config_php_file_test.php} (76%) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 9e9f1e27e67..858158ad745 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -27,8 +27,8 @@ $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -extract($phpbb_config_php_handler->get_all()); +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -38,7 +38,7 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); diff --git a/phpBB/common.php b/phpBB/common.php index b5aaedd6e0b..a1dfe2a76ce 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -27,8 +27,8 @@ $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -extract($phpbb_config_php_handler->get_all()); +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +extract($phpbb_config_php_file->get_all()); if (!defined('PHPBB_INSTALLED')) { @@ -95,7 +95,7 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 5507464209b..07cc73e5ccb 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -43,8 +43,8 @@ $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); - $phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); - extract($phpbb_config_php_handler->get_all()); + $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); + extract($phpbb_config_php_file->get_all()); if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { @@ -61,7 +61,7 @@ $phpbb_class_loader_ext->register(); // Set up container - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 392bb2ad8ce..2b12b965bed 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -62,8 +62,8 @@ function phpbb_end_update($cache, $config) $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -extract($phpbb_config_php_handler->get_all()); +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +extract($phpbb_config_php_file->get_all()); if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { @@ -86,7 +86,7 @@ function phpbb_end_update($cache, $config) set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); // Set up container (must be done here because extensions table may not exist) -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_use_kernel_pass(false); $phpbb_container_builder->set_dump_container(false); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 1c81d552a2f..040de1c8f3b 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -119,8 +119,8 @@ function phpbb_include_updated($path, $optional = false) $phpbb_class_loader_ext->register(); // Set up container -$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); $phpbb_container_builder->set_use_custom_pass(false); diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 8f77d0be9a9..f9985da1ea0 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -107,7 +107,7 @@ function install_convert(&$p_master) function main($mode, $sub) { global $lang, $template, $phpbb_root_path, $phpEx, $cache, $config, $language, $table_prefix; - global $convert, $request, $phpbb_container, $phpbb_config_php_handler; + global $convert, $request, $phpbb_container, $phpbb_config_php_file; $this->tpl_name = 'install_convert'; $this->mode = $mode; @@ -127,7 +127,7 @@ function main($mode, $sub) // Enable super globals to prevent issues with the new \phpbb\request\request object $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); // Create cache @@ -136,8 +136,8 @@ function main($mode, $sub) switch ($sub) { case 'intro': - $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); - extract($phpbb_config_php_handler->get_all()); + $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -227,8 +227,8 @@ function main($mode, $sub) // This is for making sure the session get not screwed due to the 3.0.x users table being completely new. $cache->purge(); - $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); - extract($phpbb_config_php_handler->get_all()); + $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -375,10 +375,10 @@ function list_convertors($sub) */ function get_convert_settings($sub) { - global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache, $phpbb_config_php_handler; + global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache, $phpbb_config_php_file; - $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); - extract($phpbb_config_php_handler->get_all()); + $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -621,10 +621,10 @@ function convert_data($sub) { global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth; global $convert, $convert_row, $message_parser, $skip_rows, $language; - global $request, $phpbb_config_php_handler; + global $request, $phpbb_config_php_file; - $phpbb_config_php_handler->set_config_file($phpbb_root_path . 'config.' . $phpEx); - extract($phpbb_config_php_handler->get_all()); + $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 1abe19e5b52..952c6479560 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -51,7 +51,7 @@ function install_install(&$p_master) function main($mode, $sub) { global $lang, $template, $language, $phpbb_root_path, $phpEx; - global $phpbb_container, $cache, $phpbb_log, $request, $phpbb_config_php_handler; + global $phpbb_container, $cache, $phpbb_log, $request, $phpbb_config_php_file; switch ($sub) { @@ -104,7 +104,7 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); // Sets the global variables diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 5474ae71bcc..bffb2f3365c 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -66,9 +66,9 @@ function install_update(&$p_master) function main($mode, $sub) { global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; - global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container, $phpbb_config_php_handler; + global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container, $phpbb_config_php_file; - extract($phpbb_config_php_handler->get_all()); + extract($phpbb_config_php_file->get_all()); // We must enable super globals, otherwise creating a new instance of the request class, // using the new container with a dbal connection will fail with the following PHP Notice: @@ -76,7 +76,7 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_dump_container(false); $phpbb_container_builder->set_use_extensions(false); if (file_exists($phpbb_root_path . 'install/update/new/config')) diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php_file.php similarity index 99% rename from phpBB/phpbb/config_php.php rename to phpBB/phpbb/config_php_file.php index 81910234374..5a2fbca0dd5 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php_file.php @@ -13,7 +13,7 @@ namespace phpbb; -class config_php +class config_php_file { /** @var string phpBB Root Path */ protected $phpbb_root_path; diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 426c411e07e..355d975a5f7 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 b25635d7aea..4176df9227a 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; } diff --git a/tests/config_php_test.php b/tests/config_php_file_test.php similarity index 76% rename from tests/config_php_test.php rename to tests/config_php_file_test.php index 6e2b4c2ac11..c2e4eb21c72 100644 --- a/tests/config_php_test.php +++ b/tests/config_php_file_test.php @@ -11,18 +11,18 @@ * */ -class phpbb_config_php_test extends phpbb_test_case +class phpbb_config_php_file_test extends phpbb_test_case { public function test_default() { - $config_php = new \phpbb\config_php(dirname( __FILE__ ) . '/fixtures/', 'php'); + $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); $this->assertSame('bar', $config_php->get('foo')); $this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all()); } public function test_set_config_file() { - $config_php = new \phpbb\config_php(dirname( __FILE__ ) . '/fixtures/', 'php'); + $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); $config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php'); $this->assertSame('foo', $config_php->get('bar')); $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all()); diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 57500c2ad25..221db9e13c8 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -29,7 +29,7 @@ class phpbb_di_container_test extends \phpbb_test_case public function setUp() { $this->phpbb_root_path = dirname(__FILE__) . '/'; - $this->config_php = new \phpbb\config_php($this->phpbb_root_path . 'fixtures/', 'php'); + $this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php'); $this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); $this->filename = $this->phpbb_root_path . '../tmp/container.php'; From f2e8e928c08809202b1abf5668a46e3d9e735c38 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 00:35:46 +0200 Subject: [PATCH 23/34] [ticket/12775] Fix container_builder PHPBB3-12775 --- phpBB/bin/phpbbcli.php | 2 +- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/install/database_update.php | 2 +- phpBB/install/index.php | 2 +- phpBB/install/install_convert.php | 2 +- phpBB/install/install_install.php | 2 +- phpBB/install/install_update.php | 2 +- phpBB/phpbb/di/container_builder.php | 2 +- tests/di/create_container_test.php | 2 +- tests/mock/phpbb_di_container_builder.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 858158ad745..c8098094a21 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -38,7 +38,7 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); diff --git a/phpBB/common.php b/phpBB/common.php index a1dfe2a76ce..0dfd29dfdb1 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -95,7 +95,7 @@ phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 07cc73e5ccb..d4e0f04d2b2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -61,7 +61,7 @@ $phpbb_class_loader_ext->register(); // Set up container - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 2b12b965bed..fc68235ec83 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -86,7 +86,7 @@ function phpbb_end_update($cache, $config) set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); // Set up container (must be done here because extensions table may not exist) -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_use_kernel_pass(false); $phpbb_container_builder->set_dump_container(false); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 040de1c8f3b..d18dbce52a8 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -120,7 +120,7 @@ function phpbb_include_updated($path, $optional = false) // Set up container $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); -$phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); +$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); $phpbb_container_builder->set_use_custom_pass(false); diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index f9985da1ea0..1f2b28251e9 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -127,7 +127,7 @@ function main($mode, $sub) // Enable super globals to prevent issues with the new \phpbb\request\request object $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); // Create cache diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 952c6479560..b82df84a00f 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -104,7 +104,7 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container = $phpbb_container_builder->get_container(); // Sets the global variables diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index bffb2f3365c..f8e8c53b2ab 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -76,7 +76,7 @@ function main($mode, $sub) $request->enable_super_globals(); // Create a normal container now - $phpbb_container_builder = new \phpbb\di\container_factory($phpbb_config_php_file, $phpbb_root_path, $phpEx); + $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_dump_container(false); $phpbb_container_builder->set_use_extensions(false); if (file_exists($phpbb_root_path . 'install/update/new/config')) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 355d975a5f7..f78b9e60f8a 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -16,7 +16,7 @@ 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; diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 221db9e13c8..559c0b122c1 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -20,7 +20,7 @@ class phpbb_di_container_test extends \phpbb_test_case protected $config_php; /** - * @var \phpbb\di\container_factory + * @var \phpbb\di\container_builder */ protected $builder; protected $phpbb_root_path; diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php index 235fa32b267..59cdf0bb2bc 100644 --- a/tests/mock/phpbb_di_container_builder.php +++ b/tests/mock/phpbb_di_container_builder.php @@ -11,7 +11,7 @@ * */ -class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_factory +class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder { protected function get_container_filename() { From 15c23e60b8e4b78c68286ae76e03a12b81393159 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 18:39:19 +0200 Subject: [PATCH 24/34] [ticket/12775] Update doc blocks PHPBB3-12775 --- phpBB/common.php | 1 - phpBB/install/database_update.php | 1 - phpBB/phpbb/config_php_file.php | 8 ++++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 0dfd29dfdb1..f6586c40fe9 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -23,7 +23,6 @@ require($phpbb_root_path . 'includes/startup.' . $phpEx); require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); -// Setup class loader first $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index fc68235ec83..c54c84cdbc5 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -58,7 +58,6 @@ function phpbb_end_update($cache, $config) require($phpbb_root_path . 'includes/startup.' . $phpEx); require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); -// Setup class loader first $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index 5a2fbca0dd5..ba8d3a0d9d5 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 @@ public function set_config_file($config_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. */ From 98e8be966bd8174c2a3f4e8fb80167b23573441f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 21:47:00 +0200 Subject: [PATCH 25/34] [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(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index f78b9e60f8a..fbbe736e47e 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -273,7 +273,6 @@ public function set_custom_parameters($custom_parameters) */ 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 4176df9227a..ec2d7f6e449 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -39,7 +39,7 @@ public function __construct(\phpbb\config_php_file $config_php) */ 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'))); From ed812a9dfb59b1eb83263adbaa52723ff826a791 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 29 Jun 2014 21:58:17 +0200 Subject: [PATCH 26/34] [ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class PHPBB3-12775 --- phpBB/includes/functions.php | 46 ------------------ .../includes/questionnaire/questionnaire.php | 7 ++- phpBB/install/convertors/convert_phpbb20.php | 5 +- phpBB/install/install_convert.php | 11 +++-- phpBB/install/install_update.php | 2 +- phpBB/phpbb/config_php_file.php | 47 +++++++++++++++++++ phpBB/phpbb/di/container_builder.php | 2 +- phpBB/phpbb/di/extension/config.php | 2 +- .../functions/convert_30_dbms_to_31_test.php | 3 +- .../phpbb_test_case_helpers.php | 20 +++----- 10 files changed, 73 insertions(+), 72 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9d5770069de..158bf1cbc0c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5326,52 +5326,6 @@ function phpbb_to_numeric($input) return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } -/** -* 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 db driver class -*/ -function phpbb_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"); -} - /** * Get the board contact details (e.g. for emails) * diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index b4b01a74bff..302419618ef 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -258,10 +258,13 @@ function get_identifier() function get_data() { global $phpbb_root_path, $phpEx; - include("{$phpbb_root_path}config.$phpEx"); + + $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); + $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); + extract($phpbb_config_php_file->get_all()); unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); // Only send certain config vars $config_vars = array( diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 6b6eabe57d0..4c6fa46190c 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -25,10 +25,11 @@ exit; } -include($phpbb_root_path . 'config.' . $phpEx); +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +extract($phpbb_config_php_file->get_all()); unset($dbpasswd); -$dbms = phpbb_convert_30_dbms_to_31($dbms); +$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); /** * $convertor_data provides some basic information about this convertor which is diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 1f2b28251e9..4a37ad19b93 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -142,7 +142,7 @@ function main($mode, $sub) require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); @@ -233,7 +233,7 @@ function main($mode, $sub) require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); @@ -383,7 +383,7 @@ function get_convert_settings($sub) require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); @@ -465,7 +465,8 @@ function get_convert_settings($sub) { $error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix); } - $src_dbms = phpbb_convert_30_dbms_to_31($src_dbms); + + $src_dbms = $phpbb_config_php_file->convert_30_dbms_to_31($src_dbms); // Check table prefix if (!sizeof($error)) @@ -629,7 +630,7 @@ function convert_data($sub) require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index f8e8c53b2ab..ac892145903 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -103,7 +103,7 @@ function main($mode, $sub) define('MERGE_NEW_FILE', 3); define('MERGE_MOD_FILE', 4); - $dbms = phpbb_convert_30_dbms_to_31($dbms); + $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index ba8d3a0d9d5..c0aa3567e63 100644 --- a/phpBB/phpbb/config_php_file.php +++ b/phpBB/phpbb/config_php_file.php @@ -124,4 +124,51 @@ protected function load_config_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 fbbe736e47e..95b82b26c7f 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -302,7 +302,7 @@ 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')); + $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 ec2d7f6e449..27ebc94baed 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -42,7 +42,7 @@ public function load(array $config, ContainerBuilder $container) $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')); diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php index a3992aef5c6..729c0a82f03 100644 --- a/tests/functions/convert_30_dbms_to_31_test.php +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -36,7 +36,8 @@ public function test_convert_30_dbms_to_31($input) { $expected = "phpbb\\db\\driver\\$input"; - $output = phpbb_convert_30_dbms_to_31($input); + $config_php_file = new \phpbb\config_php_file('', ''); + $output = $config_php_file->convert_30_dbms_to_31($input); $this->assertEquals($expected, $output); } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index a29b6e1955b..ade1bf6e237 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -142,17 +142,16 @@ static public function get_test_config() $test_config = dirname(__FILE__) . '/../test_config.php'; } + $config_php_file = new \phpbb\config_php_file('', ''); + if (file_exists($test_config)) { - include($test_config); - - if (!function_exists('phpbb_convert_30_dbms_to_31')) - { - require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - } + $config_php_file->set_config_file($test_config); + extract($config_php_file->get_all()); + unset($dbpasswd); $config = array_merge($config, array( - 'dbms' => phpbb_convert_30_dbms_to_31($dbms), + 'dbms' => $config_php_file->convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, @@ -183,13 +182,8 @@ static public function get_test_config() if (isset($_SERVER['PHPBB_TEST_DBMS'])) { - if (!function_exists('phpbb_convert_30_dbms_to_31')) - { - require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - } - $config = array_merge($config, array( - 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', + 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $config_php_file->convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', From d226a73111063194bac700c4236cb43dacd3ffc7 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 00:51:01 +0200 Subject: [PATCH 27/34] [ticket/12775] Remove useless includes of config.php PHPBB3-12775 --- phpBB/includes/questionnaire/questionnaire.php | 4 +--- phpBB/install/install_convert.php | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index 302419618ef..63ea4328635 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -257,10 +257,8 @@ function get_identifier() */ function get_data() { - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_config_php_file; - $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); - $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); extract($phpbb_config_php_file->get_all()); unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 4a37ad19b93..17161b5eae1 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -136,7 +136,6 @@ function main($mode, $sub) switch ($sub) { case 'intro': - $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -227,7 +226,6 @@ function main($mode, $sub) // This is for making sure the session get not screwed due to the 3.0.x users table being completely new. $cache->purge(); - $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -377,7 +375,6 @@ function get_convert_settings($sub) { global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache, $phpbb_config_php_file; - $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -624,7 +621,6 @@ function convert_data($sub) global $convert, $convert_row, $message_parser, $skip_rows, $language; global $request, $phpbb_config_php_file; - $phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx); extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); From 35c0b6d77ac1f42c1e76b7c15469b025cd50845e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 00:51:28 +0200 Subject: [PATCH 28/34] [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(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 95b82b26c7f..4b6fb6d20b3 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; } From 8c0d179e3e43c6c9e2e8e95d26c1dbdb80c26f36 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 01:01:48 +0200 Subject: [PATCH 29/34] [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(-) diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index c0aa3567e63..1a562e470de 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 @@ protected function load_config_file() { if (file_exists($this->config_file)) { - $this->defined_vars = null; $this->defined_vars = get_defined_vars(); require($this->config_file); From 6c57fbecac3aff2341fc874a911b3f296252ee3e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 01:05:55 +0200 Subject: [PATCH 30/34] [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(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 4b6fb6d20b3..9cf29c89298 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -153,7 +153,7 @@ public function get_container() 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 @@ public function get_container() } } - $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 @@ protected function get_dbal_connection() { 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 @@ protected function get_dbal_connection() 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 . ' From 285656a6d4b708c2ff40b85c591ef361114ca717 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 21:46:33 +0200 Subject: [PATCH 31/34] [ticket/12775] Extract the vars later in install/install_update.php PHPBB3-12775 --- phpBB/install/install_update.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index ac892145903..28777a8d24b 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -68,8 +68,6 @@ function main($mode, $sub) global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container, $phpbb_config_php_file; - extract($phpbb_config_php_file->get_all()); - // We must enable super globals, otherwise creating a new instance of the request class, // using the new container with a dbal connection will fail with the following PHP Notice: // Object of class phpbb_request_deactivated_super_global could not be converted to int @@ -95,6 +93,7 @@ function main($mode, $sub) $this->new_location = $phpbb_root_path . 'install/update/new/'; // Init DB + extract($phpbb_config_php_file->get_all()); require($phpbb_root_path . 'includes/constants.' . $phpEx); // Special options for conflicts/modified files From 5b11ee8c97e88367fc39b90b6a871e3bf16f7d1e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 4 Jul 2014 21:36:25 +0200 Subject: [PATCH 32/34] [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(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 9cf29c89298..65db92ada06 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -183,8 +183,7 @@ public function get_container() $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 @@ protected function inject_dbal() { if ($this->dbal_connection !== null) { - $this->container->set('dbal.conn', $this->dbal_connection); + $this->container->get('dbal.conn')->set_driver($this->dbal_connection); } } From e2cbaf4f1a0b0ddcba45babbe922076ff149a83d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 7 Jul 2014 00:08:34 +0200 Subject: [PATCH 33/34] [ticket/12775] Add the definition of dbal.conn in fixtures/config/services.yml PHPBB3-12775 --- phpBB/phpbb/di/container_builder.php | 5 ++++- tests/di/fixtures/config/services.yml | 11 ++++++++--- tests/di/fixtures/other_config/services.yml | 11 ++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 65db92ada06..ab10073013b 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -183,7 +183,10 @@ public function get_container() $this->container->set('config.php', $this->config_php_file); - $this->inject_dbal(); + if ($this->compile_container) + { + $this->inject_dbal(); + } return $this->container; } diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml index 71bc14f69a1..f2a22ae1093 100644 --- a/tests/di/fixtures/config/services.yml +++ b/tests/di/fixtures/config/services.yml @@ -2,8 +2,13 @@ parameters: core: true services: - dispatcher: - class: phpbb\db\driver\container_mock - config.php: synthetic: true + + dbal.conn: + class: phpbb\db\driver\factory + arguments: + - @service_container + + dispatcher: + class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml index 5974d3b7585..c299bfc648f 100644 --- a/tests/di/fixtures/other_config/services.yml +++ b/tests/di/fixtures/other_config/services.yml @@ -2,8 +2,13 @@ parameters: other_config: true services: - dispatcher: - class: phpbb\db\driver\container_mock - config.php: synthetic: true + + dbal.conn: + class: phpbb\db\driver\factory + arguments: + - @service_container + + dispatcher: + class: phpbb\db\driver\container_mock From 58a52fe5b90215d090ba3b992f96d401d805440c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 7 Jul 2014 01:10:24 +0200 Subject: [PATCH 34/34] [ticket/12775] Set dbal.conn.driver as synthetic during installation PHPBB3-12775 --- phpBB/install/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index d18dbce52a8..d443c537fa2 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -140,7 +140,7 @@ function phpbb_include_updated($path, $optional = false) )); $phpbb_container = $phpbb_container_builder->get_container(); -$phpbb_container->register('dbal.conn')->setSynthetic(true); +$phpbb_container->register('dbal.conn.driver')->setSynthetic(true); $phpbb_container->compile(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));