Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/12775] Replace functions_container with a container_builder class. #2671

Merged
merged 34 commits into from Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cdf87e0
[ticket/12775] Add a conter_factory class and remove functions_container
Nicofuma Jun 26, 2014
8620545
[ticket/12775] Add customs parameters
Nicofuma Jun 27, 2014
cbe846a
[ticket/12775] Don't assign $container to null
Nicofuma Jun 27, 2014
301d9ce
[ticket/12775] Add a config.php class (and service)
Nicofuma Jun 27, 2014
b999540
[ticket/12775] Add get() and get_all() into config_php
Nicofuma Jun 27, 2014
01c25d3
[ticket/12775] Use the config.php handler in \phpbb\config_php
Nicofuma Jun 27, 2014
4f56f9b
[ticket/12775] Rename the variables into common.php
Nicofuma Jun 27, 2014
98890fe
[ticket/12775] Fix config_php::load_config_file()
Nicofuma Jun 27, 2014
7864851
[ticket/12775] Update phpBB/bin/phpbbcli.php
Nicofuma Jun 27, 2014
f87e76b
[ticket/12775] Update phpBB/download/file.php
Nicofuma Jun 27, 2014
e7804ec
[ticket/12775] Update phpBB/install/database_update.php
Nicofuma Jun 27, 2014
ef1346c
[ticket/12775] Update phpBB/install/index.php
Nicofuma Jun 27, 2014
20912d7
[ticket/12775] Skip the tests related to the container
Nicofuma Jun 27, 2014
cefffe0
[ticket/12775] Load the config file before constants.php
Nicofuma Jun 27, 2014
91ca12f
[ticket/12775] Update container and config in install/
Nicofuma Jun 27, 2014
c87f44c
[ticket/12775] Use a field instead of a local var in load_config_var()
Nicofuma Jun 27, 2014
1d966fb
[ticket/12775] Add tests for the container factory
Nicofuma Jun 27, 2014
afffec8
[ticket/12775] Add tests for \phpbb\config_php
Nicofuma Jun 27, 2014
926e47e
[ticket/12775] Fix unit tests
Nicofuma Jun 28, 2014
11ff91c
[ticket/12775] Remove the last include of functions_container
Nicofuma Jun 28, 2014
40937e2
[ticket/12775] Renamed to \phpbb\di\container_builder
Nicofuma Jun 28, 2014
2db160f
[ticket/12775] Rename config_php to config_php_file
Nicofuma Jun 28, 2014
f2e8e92
[ticket/12775] Fix container_builder
Nicofuma Jun 28, 2014
15c23e6
[ticket/12775] Update doc blocks
Nicofuma Jun 29, 2014
98e8be9
[ticket/12775] Fix comments
Nicofuma Jun 29, 2014
ed812a9
[ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file …
Nicofuma Jun 29, 2014
d226a73
[ticket/12775] Remove useless includes of config.php
Nicofuma Jun 29, 2014
35c0b6d
[ticket/12775] Fix doc blocks in the container builder
Nicofuma Jun 29, 2014
8c0d179
[ticket/12775] Set defined_vars as a property of config_php_file
Nicofuma Jun 29, 2014
6c57fbe
[ticket/12775] Rename config_php_handler to config_php_file container…
Nicofuma Jun 29, 2014
285656a
[ticket/12775] Extract the vars later in install/install_update.php
Nicofuma Jun 30, 2014
5b11ee8
[ticket/12775] Inject the connection when created in the container
Nicofuma Jul 4, 2014
e2cbaf4
[ticket/12775] Add the definition of dbal.conn in fixtures/config/ser…
Nicofuma Jul 6, 2014
58a52fe
[ticket/12775] Set dbal.conn.driver as synthetic during installation
Nicofuma Jul 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions phpBB/bin/phpbbcli.php
Expand Up @@ -22,20 +22,27 @@
$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 . 'phpbb/class_loader.' . $phpEx);

$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();

$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);
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);

$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_container = phpbb_create_update_container($phpbb_root_path, $phpEx, "$phpbb_root_path/config");
$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx);
$phpbb_container_builder->set_use_extensions(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we can easily remove this later on to also have the extensions loaded? This would fix https://tracker.phpbb.com/browse/PHPBB3-12685

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think too, and this way we could have a "safe" phpbbcli (no cache, no extensions...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that later as a PR on top of this.

$phpbb_container_builder->set_dump_container(false);

$phpbb_container = $phpbb_container_builder->get_container();
$phpbb_container->get('request')->enable_super_globals();
require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx);

Expand Down
19 changes: 8 additions & 11 deletions phpBB/common.php
Expand Up @@ -21,11 +21,13 @@
}

require($phpbb_root_path . 'includes/startup.' . $phpEx);
require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);

if (file_exists($phpbb_root_path . 'config.' . $phpEx))
{
require($phpbb_root_path . 'config.' . $phpEx);
}
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();

$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
extract($phpbb_config_php_file->get_all());

if (!defined('PHPBB_INSTALLED'))
{
Expand Down Expand Up @@ -76,11 +78,8 @@
$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);
include($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx);

require($phpbb_root_path . 'includes/constants.' . $phpEx);
Expand All @@ -89,16 +88,14 @@
// 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
$phpbb_container = phpbb_create_default_container($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'));
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
Expand Down
6 changes: 3 additions & 3 deletions phpBB/config/services.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -69,6 +66,9 @@ services:
- @cache.driver
- %tables.config%

config.php:
synthetic: true

config_text:
class: phpbb\config\db_text
arguments:
Expand Down
18 changes: 9 additions & 9 deletions phpBB/download/file.php
Expand Up @@ -38,31 +38,31 @@
if (isset($_GET['avatar']))
{
require($phpbb_root_path . 'includes/startup.' . $phpEx);
require($phpbb_root_path . 'config.' . $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_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))
{
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_container.' . $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);

// Set up container
$phpbb_container = phpbb_create_default_container($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'));
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
Expand Down
46 changes: 0 additions & 46 deletions phpBB/includes/functions.php
Expand Up @@ -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)
*
Expand Down