diff options
author | Nils Adermann <naderman@naderman.de> | 2014-11-21 18:20:19 +0100 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2014-11-21 18:20:19 +0100 |
commit | 040d451dcca9ae54d8f4b7bdd2f231033765a8f2 (patch) | |
tree | 28ac46737634c2eae0a2228fcb9b66360dd5cc2e | |
parent | 6fa0ca1f96fa75624ab2b4fca8b390568440b3c1 (diff) | |
parent | 54d529994029564d5cecbec2aaac36a0544552a0 (diff) | |
download | forums-040d451dcca9ae54d8f4b7bdd2f231033765a8f2.tar forums-040d451dcca9ae54d8f4b7bdd2f231033765a8f2.tar.gz forums-040d451dcca9ae54d8f4b7bdd2f231033765a8f2.tar.bz2 forums-040d451dcca9ae54d8f4b7bdd2f231033765a8f2.tar.xz forums-040d451dcca9ae54d8f4b7bdd2f231033765a8f2.zip |
Merge pull request #2883 from Nicofuma/ticket/12620
[ticket/12620] Allow the user to define multiples environments
76 files changed, 771 insertions, 404 deletions
diff --git a/build/build.xml b/build/build.xml index 5d143886af..16798f0e97 100644 --- a/build/build.xml +++ b/build/build.xml @@ -283,6 +283,8 @@ <delete file="${dir}/config.php" /> <delete dir="${dir}/develop" /> <delete dir="${dir}/install/data" /> + <delete dir="${dir}/config/development" /> + <delete dir="${dir}/config/test" /> <phingcall target="clean-vendor-dir"> <property name="dir" value="${dir}" /> diff --git a/phpBB/app.php b/phpBB/app.php index d9250adc75..10909f7103 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -21,7 +21,6 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($phpbb_root_path . 'includes/functions_url_matcher.' . $phpEx); // Start session management $user->session_begin(); diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index ca425ad0c4..14681e25ee 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -21,6 +21,12 @@ if (php_sapi_name() != 'cli') } define('IN_PHPBB', true); + +if (!defined('PHPBB_ENVIRONMENT')) +{ + @define('PHPBB_ENVIRONMENT', 'production'); +} + $phpbb_root_path = __DIR__ . '/../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require($phpbb_root_path . 'includes/startup.' . $phpEx); diff --git a/phpBB/common.php b/phpBB/common.php index 0782bd7321..2fa0c46b22 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -29,6 +29,11 @@ $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_ENVIRONMENT')) +{ + @define('PHPBB_ENVIRONMENT', 'production'); +} + if (!defined('PHPBB_INSTALLED')) { // Redirect the user to the installer @@ -94,8 +99,18 @@ $phpbb_class_loader_ext->register(); phpbb_load_extensions_autoloaders($phpbb_root_path); // Set up container -$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); -$phpbb_container = $phpbb_container_builder->get_container(); +try +{ + $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); + $phpbb_container = $phpbb_container_builder->get_container(); +} +catch (InvalidArgumentException $e) +{ + trigger_error( + 'The requested environment ' . PHPBB_ENVIRONMENT . ' is not available.', + E_USER_ERROR + ); +} $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/default/config.yml b/phpBB/config/default/config.yml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/phpBB/config/default/config.yml diff --git a/phpBB/config/parameters.yml b/phpBB/config/default/container/parameters.yml index 8ecc1428f4..8ecc1428f4 100644 --- a/phpBB/config/parameters.yml +++ b/phpBB/config/default/container/parameters.yml diff --git a/phpBB/config/services.yml b/phpBB/config/default/container/services.yml index f6dbae4a76..6cf9180cc0 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/default/container/services.yml @@ -1,19 +1,19 @@ imports: - - { resource: auth.yml } - - { resource: avatar.yml } - - { resource: captcha.yml } - - { resource: console.yml } - - { resource: content.yml } - - { resource: cron.yml } - - { resource: db.yml } - - { resource: event.yml } - - { resource: feed.yml } - - { resource: mimetype_guesser.yml } - - { resource: notification.yml } - - { resource: password.yml } - - { resource: profilefield.yml } - - { resource: twig.yml } - - { resource: user.yml } + - { resource: services_auth.yml } + - { resource: services_avatar.yml } + - { resource: services_captcha.yml } + - { resource: services_console.yml } + - { resource: services_content.yml } + - { resource: services_cron.yml } + - { resource: services_db.yml } + - { resource: services_event.yml } + - { resource: services_feed.yml } + - { resource: services_mimetype_guesser.yml } + - { resource: services_notification.yml } + - { resource: services_password.yml } + - { resource: services_profilefield.yml } + - { resource: services_twig.yml } + - { resource: services_user.yml } - { resource: tables.yml } - { resource: parameters.yml } @@ -157,6 +157,7 @@ services: - @ext.manager - %core.root_path% - %core.php_ext% + - %core.environment% router.listener: class: Symfony\Component\HttpKernel\EventListener\RouterListener diff --git a/phpBB/config/auth.yml b/phpBB/config/default/container/services_auth.yml index 88a90ca2d6..88a90ca2d6 100644 --- a/phpBB/config/auth.yml +++ b/phpBB/config/default/container/services_auth.yml diff --git a/phpBB/config/avatar.yml b/phpBB/config/default/container/services_avatar.yml index 5292489715..5292489715 100644 --- a/phpBB/config/avatar.yml +++ b/phpBB/config/default/container/services_avatar.yml diff --git a/phpBB/config/captcha.yml b/phpBB/config/default/container/services_captcha.yml index e3f617e909..e3f617e909 100644 --- a/phpBB/config/captcha.yml +++ b/phpBB/config/default/container/services_captcha.yml diff --git a/phpBB/config/console.yml b/phpBB/config/default/container/services_console.yml index 1e18a7dd37..1e18a7dd37 100644 --- a/phpBB/config/console.yml +++ b/phpBB/config/default/container/services_console.yml diff --git a/phpBB/config/content.yml b/phpBB/config/default/container/services_content.yml index f0985f0292..f0985f0292 100644 --- a/phpBB/config/content.yml +++ b/phpBB/config/default/container/services_content.yml diff --git a/phpBB/config/cron.yml b/phpBB/config/default/container/services_cron.yml index 7a90c39733..7a90c39733 100644 --- a/phpBB/config/cron.yml +++ b/phpBB/config/default/container/services_cron.yml diff --git a/phpBB/config/db.yml b/phpBB/config/default/container/services_db.yml index b3f1b485ea..b3f1b485ea 100644 --- a/phpBB/config/db.yml +++ b/phpBB/config/default/container/services_db.yml diff --git a/phpBB/config/event.yml b/phpBB/config/default/container/services_event.yml index 1ccef78f9b..1ccef78f9b 100644 --- a/phpBB/config/event.yml +++ b/phpBB/config/default/container/services_event.yml diff --git a/phpBB/config/feed.yml b/phpBB/config/default/container/services_feed.yml index 48bd9fe76f..48bd9fe76f 100644 --- a/phpBB/config/feed.yml +++ b/phpBB/config/default/container/services_feed.yml diff --git a/phpBB/config/default/container/services_migrator.yml b/phpBB/config/default/container/services_migrator.yml new file mode 100644 index 0000000000..cd04eea5c2 --- /dev/null +++ b/phpBB/config/default/container/services_migrator.yml @@ -0,0 +1,60 @@ +services: + migrator: + class: phpbb\db\migrator + arguments: + - @config + - @dbal.conn + - @dbal.tools + - %tables.migrations% + - %core.root_path% + - %core.php_ext% + - %core.table_prefix% + - @migrator.tool_collection + - @migrator.helper + + migrator.helper: + class: phpbb\db\migration\helper + + migrator.tool_collection: + class: phpbb\di\service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: migrator.tool } + + migrator.tool.config: + class: phpbb\db\migration\tool\config + arguments: + - @config + tags: + - { name: migrator.tool } + + migrator.tool.config_text: + class: phpbb\db\migration\tool\config_text + arguments: + - @config_text + tags: + - { name: migrator.tool } + + migrator.tool.module: + class: phpbb\db\migration\tool\module + arguments: + - @dbal.conn + - @cache + - @user + - %core.root_path% + - %core.php_ext% + - %tables.modules% + tags: + - { name: migrator.tool } + + migrator.tool.permission: + class: phpbb\db\migration\tool\permission + arguments: + - @dbal.conn + - @cache + - @auth + - %core.root_path% + - %core.php_ext% + tags: + - { name: migrator.tool } diff --git a/phpBB/config/mimetype_guesser.yml b/phpBB/config/default/container/services_mimetype_guesser.yml index 2e89ed3c1f..2e89ed3c1f 100644 --- a/phpBB/config/mimetype_guesser.yml +++ b/phpBB/config/default/container/services_mimetype_guesser.yml diff --git a/phpBB/config/notification.yml b/phpBB/config/default/container/services_notification.yml index add577be2c..add577be2c 100644 --- a/phpBB/config/notification.yml +++ b/phpBB/config/default/container/services_notification.yml diff --git a/phpBB/config/password.yml b/phpBB/config/default/container/services_password.yml index cb45ec3d42..cb45ec3d42 100644 --- a/phpBB/config/password.yml +++ b/phpBB/config/default/container/services_password.yml diff --git a/phpBB/config/profilefield.yml b/phpBB/config/default/container/services_profilefield.yml index 5ccfef9148..5ccfef9148 100644 --- a/phpBB/config/profilefield.yml +++ b/phpBB/config/default/container/services_profilefield.yml diff --git a/phpBB/config/twig.yml b/phpBB/config/default/container/services_twig.yml index 0745d8b47e..fc5f9ba6a1 100644 --- a/phpBB/config/twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -1,5 +1,5 @@ parameters: - core.template.cache_path: %core.root_path%cache/twig/ + core.template.cache_path: %core.root_path%cache/%core.environment%/twig/ services: template.twig.environment: diff --git a/phpBB/config/user.yml b/phpBB/config/default/container/services_user.yml index 1ca853ea45..1ca853ea45 100644 --- a/phpBB/config/user.yml +++ b/phpBB/config/default/container/services_user.yml diff --git a/phpBB/config/tables.yml b/phpBB/config/default/container/tables.yml index 2fe2a33be8..2fe2a33be8 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/default/container/tables.yml diff --git a/phpBB/config/routing.yml b/phpBB/config/default/routing/routing.yml index d8e890d063..d8e890d063 100644 --- a/phpBB/config/routing.yml +++ b/phpBB/config/default/routing/routing.yml diff --git a/phpBB/config/development/config.yml b/phpBB/config/development/config.yml new file mode 100644 index 0000000000..1c17b08931 --- /dev/null +++ b/phpBB/config/development/config.yml @@ -0,0 +1,5 @@ +imports: + - { resource: ../default/config.yml } + +core: + require_dev_dependencies: true diff --git a/phpBB/config/development/container/environment.yml b/phpBB/config/development/container/environment.yml new file mode 100644 index 0000000000..40a3c7a683 --- /dev/null +++ b/phpBB/config/development/container/environment.yml @@ -0,0 +1,3 @@ +imports: + - { resource: services.yml } + - { resource: parameters.yml } diff --git a/phpBB/config/development/container/parameters.yml b/phpBB/config/development/container/parameters.yml new file mode 100644 index 0000000000..0447646806 --- /dev/null +++ b/phpBB/config/development/container/parameters.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/parameters.yml } diff --git a/phpBB/config/development/container/services.yml b/phpBB/config/development/container/services.yml new file mode 100644 index 0000000000..b302f0f966 --- /dev/null +++ b/phpBB/config/development/container/services.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/services.yml } diff --git a/phpBB/config/development/routing/environment.yml b/phpBB/config/development/routing/environment.yml new file mode 100644 index 0000000000..0cddfb7521 --- /dev/null +++ b/phpBB/config/development/routing/environment.yml @@ -0,0 +1,2 @@ +core.default: + resource: "../../default/routing/routing.yml" diff --git a/phpBB/config/production/config.yml b/phpBB/config/production/config.yml new file mode 100644 index 0000000000..979dbbcdd9 --- /dev/null +++ b/phpBB/config/production/config.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../default/config.yml } diff --git a/phpBB/config/production/container/environment.yml b/phpBB/config/production/container/environment.yml new file mode 100644 index 0000000000..40a3c7a683 --- /dev/null +++ b/phpBB/config/production/container/environment.yml @@ -0,0 +1,3 @@ +imports: + - { resource: services.yml } + - { resource: parameters.yml } diff --git a/phpBB/config/production/container/parameters.yml b/phpBB/config/production/container/parameters.yml new file mode 100644 index 0000000000..0447646806 --- /dev/null +++ b/phpBB/config/production/container/parameters.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/parameters.yml } diff --git a/phpBB/config/production/container/services.yml b/phpBB/config/production/container/services.yml new file mode 100644 index 0000000000..b302f0f966 --- /dev/null +++ b/phpBB/config/production/container/services.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/services.yml } diff --git a/phpBB/config/production/routing/environment.yml b/phpBB/config/production/routing/environment.yml new file mode 100644 index 0000000000..0cddfb7521 --- /dev/null +++ b/phpBB/config/production/routing/environment.yml @@ -0,0 +1,2 @@ +core.default: + resource: "../../default/routing/routing.yml" diff --git a/phpBB/config/test/config.yml b/phpBB/config/test/config.yml new file mode 100644 index 0000000000..1c17b08931 --- /dev/null +++ b/phpBB/config/test/config.yml @@ -0,0 +1,5 @@ +imports: + - { resource: ../default/config.yml } + +core: + require_dev_dependencies: true diff --git a/phpBB/config/test/container/environment.yml b/phpBB/config/test/container/environment.yml new file mode 100644 index 0000000000..40a3c7a683 --- /dev/null +++ b/phpBB/config/test/container/environment.yml @@ -0,0 +1,3 @@ +imports: + - { resource: services.yml } + - { resource: parameters.yml } diff --git a/phpBB/config/test/container/parameters.yml b/phpBB/config/test/container/parameters.yml new file mode 100644 index 0000000000..0447646806 --- /dev/null +++ b/phpBB/config/test/container/parameters.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/parameters.yml } diff --git a/phpBB/config/test/container/services.yml b/phpBB/config/test/container/services.yml new file mode 100644 index 0000000000..b302f0f966 --- /dev/null +++ b/phpBB/config/test/container/services.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../../default/container/services.yml } diff --git a/phpBB/config/test/routing/environment.yml b/phpBB/config/test/routing/environment.yml new file mode 100644 index 0000000000..0cddfb7521 --- /dev/null +++ b/phpBB/config/test/routing/environment.yml @@ -0,0 +1,2 @@ +core.default: + resource: "../../default/routing/routing.yml" diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 77fb455bc1..4b8309c70e 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -42,6 +42,11 @@ if (isset($_GET['avatar'])) $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); extract($phpbb_config_php_file->get_all()); + if (!defined('PHPBB_ENVIRONMENT')) + { + @define('PHPBB_ENVIRONMENT', 'production'); + } + if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { exit; diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 28cc603bdb..a60ddd40c5 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -451,13 +451,17 @@ function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_cont $config_data .= "\n@define('PHPBB_INSTALLED', true);\n"; $config_data .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n"; - if ($debug) + if ($debug_test) + { + $config_data .= "@define('PHPBB_ENVIRONMENT', 'test');\n"; + } + else if ($debug) { - $config_data .= "@define('DEBUG', true);\n"; + $config_data .= "@define('PHPBB_ENVIRONMENT', 'development');\n"; } else { - $config_data .= "// @define('DEBUG', true);\n"; + $config_data .= "@define('PHPBB_ENVIRONMENT', 'production');\n"; } if ($debug_container) @@ -472,6 +476,7 @@ function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_cont if ($debug_test) { $config_data .= "@define('DEBUG_TEST', true);\n"; + $config_data .= "@define('DEBUG', true);\n"; // Mandatory for the functional tests, will be removed by PHPBB3-12623 } return $config_data; diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php deleted file mode 100644 index b965046aad..0000000000 --- a/phpBB/includes/functions_url_matcher.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @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\Routing\Matcher\Dumper\PhpMatcherDumper; -use Symfony\Component\Routing\Matcher\UrlMatcher; -use Symfony\Component\Routing\RequestContext; - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** -* Create a new UrlMatcher class and dump it into the cache file -* -* @param \phpbb\extension\manager $manager Extension manager -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP file extension -* @return null -*/ -function phpbb_get_url_matcher(\phpbb\extension\manager $manager, RequestContext $context, $root_path, $php_ext) -{ - if (defined('DEBUG')) - { - return phpbb_create_url_matcher($manager, $context, $root_path); - } - - if (!phpbb_url_matcher_dumped($root_path, $php_ext)) - { - phpbb_create_dumped_url_matcher($manager, $root_path, $php_ext); - } - - return phpbb_load_url_matcher($context, $root_path, $php_ext); -} - -/** -* Create a new UrlMatcher class and dump it into the cache file -* -* @param \phpbb\extension\manager $manager Extension manager -* @param string $root_path Root path -* @param string $php_ext PHP file extension -* @return null -*/ -function phpbb_create_dumped_url_matcher(\phpbb\extension\manager $manager, $root_path, $php_ext) -{ - $provider = new \phpbb\controller\provider(); - $provider->find_routing_files($manager->get_finder()); - $routes = $provider->find($root_path)->get_routes(); - $dumper = new PhpMatcherDumper($routes); - $cached_url_matcher_dump = $dumper->dump(array( - 'class' => 'phpbb_url_matcher', - )); - - file_put_contents($root_path . 'cache/url_matcher.' . $php_ext, $cached_url_matcher_dump); -} - -/** -* Create a non-cached UrlMatcher -* -* @param \phpbb\extension\manager $manager Extension manager -* @param RequestContext $context Symfony RequestContext object -* @return UrlMatcher -*/ -function phpbb_create_url_matcher(\phpbb\extension\manager $manager, RequestContext $context, $root_path) -{ - $provider = new \phpbb\controller\provider(); - $provider->find_routing_files($manager->get_finder()); - $routes = $provider->find($root_path)->get_routes(); - return new UrlMatcher($routes, $context); -} - -/** -* Load the cached phpbb_url_matcher class -* -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP file extension -* @return phpbb_url_matcher -*/ -function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext) -{ - require($root_path . 'cache/url_matcher.' . $php_ext); - return new phpbb_url_matcher($context); -} - -/** -* Determine whether we have our dumped URL matcher -* -* The class is automatically dumped to the cache directory -* -* @param string $root_path Root path -* @param string $php_ext PHP file extension -* @return bool True if it exists, false if not -*/ -function phpbb_url_matcher_dumped($root_path, $php_ext) -{ - return file_exists($root_path . 'cache/url_matcher.' . $php_ext); -} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 3dd73adc60..1cc588071b 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -16,6 +16,7 @@ */ define('IN_PHPBB', true); define('IN_INSTALL', true); +define('PHPBB_ENVIRONMENT', 'production'); /**#@-*/ $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../'; diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index adfe87b740..114959c06c 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -27,8 +27,14 @@ class file extends \phpbb\cache\driver\base */ function __construct($cache_dir = null) { - global $phpbb_root_path; - $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/'; + global $phpbb_root_path, $phpbb_container; + + $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/' . $phpbb_container->getParameter('core.environment') . '/'; + + if (!is_dir($this->cache_dir)) + { + @mkdir($this->cache_dir, 0777, true); + } } /** diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index cc327882e0..2bc8e6b9d0 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -41,8 +41,9 @@ class helper protected $config; /** - * @var \phpbb\routing\router phpBB router - */ + * phpBB router + * @var \phpbb\routing\router + */ protected $router; /* @var \phpbb\symfony_request */ diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 638c13e86d..125ae28e9b 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -13,16 +13,25 @@ namespace phpbb\di; +use Symfony\Component\Config\ConfigCache; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; +use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; +use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder { - /** @var string phpBB Root Path */ + /** + * @var string phpBB Root Path + */ protected $phpbb_root_path; - /** @var string php file extension */ + /** + * @var string php file extension + */ protected $php_ext; /** @@ -112,6 +121,11 @@ class container_builder protected $config_php_file; /** + * @var string + */ + protected $cache_dir; + + /** * Constructor * * @param \phpbb\config_php_file $config_php_file @@ -133,23 +147,30 @@ class container_builder public function get_container() { $container_filename = $this->get_container_filename(); - if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) + $config_cache = new ConfigCache($container_filename, defined('DEBUG')); + if ($this->dump_container && $config_cache->isFresh()) { require($container_filename); $this->container = new \phpbb_cache_container(); } else { - if ($this->config_path === null) - { - $this->config_path = $this->phpbb_root_path . 'config'; - } - $container_extensions = array(new \phpbb\di\extension\core($this->config_path)); + $container_extensions = array(new \phpbb\di\extension\core($this->get_config_path())); if ($this->use_extensions) { $installed_exts = $this->get_installed_extensions(); - $container_extensions[] = new \phpbb\di\extension\ext($installed_exts); + foreach ($installed_exts as $ext_name => $path) + { + $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; + + if (!class_exists($extension_class)) + { + $extension_class = '\phpbb\extension\di\extension_base'; + } + + $container_extensions[] = new $extension_class($ext_name, $path); + } } if ($this->inject_config) @@ -171,6 +192,9 @@ class container_builder } } + $loader = new YamlFileLoader($this->container, new FileLocator(phpbb_realpath($this->get_config_path()))); + $loader->load($this->container->getParameter('core.environment') . '/config.yml'); + $this->inject_custom_parameters(); if ($this->compile_container) @@ -178,9 +202,9 @@ class container_builder $this->container->compile(); } - if ($this->dump_container && !defined('DEBUG_CONTAINER')) + if ($this->dump_container) { - $this->dump_container($container_filename); + $this->dump_container($config_cache); } } @@ -267,6 +291,16 @@ class container_builder } /** + * Returns the path to the container configuration (default: root_path/config) + * + * @return string + */ + protected function get_config_path() + { + return $this->config_path ?: $this->phpbb_root_path . 'config'; + } + + /** * Set custom parameters to inject into the container. * * @param array $custom_parameters @@ -277,11 +311,31 @@ class container_builder } /** + * Set the path to the cache directory. + * + * @param string $cache_dir Path to the cache directory + */ + public function set_cache_dir($cache_dir) + { + $this->cache_dir = $cache_dir; + } + + /** + * Returns the path to the cache directory (default: root_path/cache/environment). + * + * @return string Path to the cache directory. + */ + protected function get_cache_dir() + { + return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . $this->get_environment() . '/'; + } + + /** * Dump the container to the disk. * - * @param string $container_filename The name of the file. + * @param ConfigCache $cache The config cache */ - protected function dump_container($container_filename) + protected function dump_container($cache) { $dumper = new PhpDumper($this->container); $cached_container_dump = $dumper->dump(array( @@ -289,7 +343,7 @@ class container_builder 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - file_put_contents($container_filename, $cached_container_dump); + $cache->write($cached_container_dump, $this->container->getResources()); } /** @@ -362,34 +416,73 @@ class container_builder */ protected function create_container(array $extensions) { - $container = new ContainerBuilder(); + $container = new ContainerBuilder(new ParameterBag($this->get_core_parameters())); + + $extensions_alias = array(); foreach ($extensions as $extension) { $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); + $extensions_alias[] = $extension->getAlias(); + //$container->loadFromExtension($extension->getAlias()); } + $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions_alias)); + return $container; } /** - * Inject the customs parameters into the container - */ + * Inject the customs parameters into the container + */ protected function inject_custom_parameters() { - if ($this->custom_parameters === null) + 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); + } } + } - foreach ($this->custom_parameters as $key => $value) + /** + * Returns the core parameters. + * + * @return array An array of core parameters + */ + protected function get_core_parameters() + { + return array_merge( + array( + 'core.root_path' => $this->phpbb_root_path, + 'core.php_ext' => $this->php_ext, + 'core.environment' => $this->get_environment(), + 'core.debug' => DEBUG, + ), + $this->get_env_parameters() + ); + } + + /** + * Gets the environment parameters. + * + * Only the parameters starting with "PHPBB__" are considered. + * + * @return array An array of parameters + */ + protected function get_env_parameters() + { + $parameters = array(); + foreach ($_SERVER as $key => $value) { - $this->container->setParameter($key, $value); + if (0 === strpos($key, 'PHPBB__')) + { + $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; + } } + + return $parameters; } /** @@ -400,6 +493,16 @@ class container_builder 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; + return $this->get_cache_dir() . 'container_' . $filename . '.' . $this->php_ext; + } + + /** + * Return the name of the current environment. + * + * @return string + */ + protected function get_environment() + { + return PHPBB_ENVIRONMENT; } } diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php new file mode 100644 index 0000000000..1f1c077472 --- /dev/null +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -0,0 +1,38 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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\extension; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class container_configuration implements ConfigurationInterface +{ + + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('core'); + $rootNode + ->children() + ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() + ->end() + ; + return $treeBuilder; + } +} diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index ca4fa5c082..72d46fb05b 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -13,10 +13,11 @@ namespace phpbb\di\extension; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * Container core extension @@ -24,42 +25,68 @@ use Symfony\Component\Config\FileLocator; class core extends Extension { /** - * Config path - * @var string - */ + * Config path + * @var string + */ protected $config_path; /** - * Constructor - * - * @param string $config_path Config path - */ + * Constructor + * + * @param string $config_path Config path + */ public function __construct($config_path) { $this->config_path = $config_path; } /** - * Loads a specific configuration. - * - * @param array $config An array of configuration values - * @param ContainerBuilder $container A ContainerBuilder instance - * - * @throws \InvalidArgumentException When provided tag is not defined in this extension - */ - public function load(array $config, ContainerBuilder $container) + * Loads a specific configuration. + * + * @param array $configs An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws \InvalidArgumentException When provided tag is not defined in this extension + */ + public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load('services.yml'); + $loader->load($container->getParameter('core.environment') . '/container/environment.yml'); + + $config = $this->getConfiguration($configs, $container); + $config = $this->processConfiguration($config, $configs); + + if ($config['require_dev_dependencies']) + { + if (!class_exists('Goutte\Client', true)) + { + trigger_error( + 'Composer development dependencies have not been set up for the ' . $container->getParameter('core.environment') . ' environment yet, run ' . + "'php ../composer.phar install --dev' from the phpBB directory to do so.", + E_USER_ERROR + ); + } + } + } + + /** + * {@inheritdoc} + */ + public function getConfiguration(array $config, ContainerBuilder $container) + { + $r = new \ReflectionClass('\phpbb\di\extension\container_configuration'); + $container->addResource(new FileResource($r->getFileName())); + + return new container_configuration(); } /** - * Returns the recommended alias to use in XML. - * - * This alias is also the mandatory prefix to use when using YAML. - * - * @return string The alias - */ + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ public function getAlias() { return 'core'; diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php deleted file mode 100644 index 718c992d2e..0000000000 --- a/phpBB/phpbb/di/extension/ext.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @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\extension; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; - -/** -* Container ext extension -*/ -class ext extends Extension -{ - protected $paths = array(); - - public function __construct($enabled_extensions) - { - foreach ($enabled_extensions as $ext => $path) - { - $this->paths[] = $path; - } - } - - /** - * Loads a specific configuration. - * - * @param array $config An array of configuration values - * @param ContainerBuilder $container A ContainerBuilder instance - * - * @throws \InvalidArgumentException When provided tag is not defined in this extension - */ - public function load(array $config, ContainerBuilder $container) - { - foreach ($this->paths as $path) - { - if (file_exists($path . '/config/services.yml')) - { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($path . '/config'))); - $loader->load('services.yml'); - } - } - } - - /** - * Returns the recommended alias to use in XML. - * - * This alias is also the mandatory prefix to use when using YAML. - * - * @return string The alias - */ - public function getAlias() - { - return 'ext'; - } -} diff --git a/phpBB/phpbb/extension/di/extension_base.php b/phpBB/phpbb/extension/di/extension_base.php new file mode 100644 index 0000000000..30cc37dbb6 --- /dev/null +++ b/phpBB/phpbb/extension/di/extension_base.php @@ -0,0 +1,137 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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\extension\di; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +/** + * Container core extension + */ +class extension_base extends Extension +{ + /** + * Name of the extension (vendor/name) + * + * @var string + */ + protected $extension_name; + + /** + * Path to the extension. + * + * @var string + */ + protected $ext_path; + + /** + * Constructor + * + * @param string $extension_name Name of the extension (vendor/name) + * @param string $ext_path Path to the extension + */ + public function __construct($extension_name, $ext_path) + { + $this->extension_name = $extension_name; + $this->ext_path = $ext_path; + } + + /** + * Loads a specific configuration. + * + * @param array $configs An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws \InvalidArgumentException When provided tag is not defined in this extension + */ + public function load(array $configs, ContainerBuilder $container) + { + $this->load_services($container); + } + + /** + * Loads the services.yml file. + * + * @param ContainerBuilder $container A ContainerBuilder instance + */ + protected function load_services(ContainerBuilder $container) + { + $services_directory = false; + $services_file = false; + + if (file_exists($this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/environment.yml')) + { + $services_directory = $this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/'; + $services_file = 'environment.yml'; + } + else if (!is_dir($this->ext_path . 'config/' . $container->getParameter('core.environment'))) + { + if (file_exists($this->ext_path . 'config/default/container/environment.yml')) + { + $services_directory = $this->ext_path . 'config/default/container/'; + $services_file = 'environment.yml'; + } + else if (!is_dir($this->ext_path . 'config/default') && file_exists($this->ext_path . '/config/services.yml')) + { + $services_directory = $this->ext_path . 'config'; + $services_file = 'services.yml'; + } + } + + if ($services_directory && $services_file) + { + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($services_directory))); + $loader->load($services_file); + } + } + + /** + * {@inheritdoc} + */ + public function getConfiguration(array $config, ContainerBuilder $container) + { + $reflected = new \ReflectionClass($this); + $namespace = $reflected->getNamespaceName(); + + $class = $namespace . '\\di\configuration'; + if (class_exists($class)) + { + $r = new \ReflectionClass($class); + $container->addResource(new FileResource($r->getFileName())); + + if (!method_exists($class, '__construct')) + { + $configuration = new $class(); + + return $configuration; + } + } + + } + + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ + public function getAlias() + { + return str_replace('/', '_', $this->extension_name); + } +} diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index f721837bba..1003708540 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -25,95 +25,121 @@ use Symfony\Component\Config\FileLocator; use phpbb\extension\manager; /** -* Integration of all pieces of the routing system for easier use. -*/ + * Integration of all pieces of the routing system for easier use. + */ class router implements RouterInterface { /** - * @var manager Extension manager - */ + * Extension manager + * + * @var manager + */ protected $extension_manager; /** - * @var string phpBB root path - */ + * phpBB root path + * + * @var string + */ protected $phpbb_root_path; /** - * @var string PHP file extensions - */ + * PHP file extensions + * + * @var string + */ protected $php_ext; /** - * @var array YAML file(s) containing route information - */ + * Name of the current environment + * + * @var string + */ + protected $environment; + + /** + * YAML file(s) containing route information + * + * @var array + */ protected $routing_files; /** - * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null - */ + * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null + */ protected $matcher; /** - * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null - */ + * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null + */ protected $generator; /** - * @var RequestContext - */ + * @var RequestContext + */ protected $context; /** - * @var RouteCollection|null - */ + * @var RouteCollection|null + */ protected $route_collection; /** - * Construct method - * - * @param manager $extension_manager The extension manager - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param array $routing_files Array of strings containing paths to YAML files holding route information - */ - public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $routing_files = array()) + * Construct method + * + * @param manager $extension_manager Extension manager + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param string $environment Name of the current environment + * @param array $routing_files Array of strings containing paths to YAML files holding route information + */ + public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array()) { $this->extension_manager = $extension_manager; $this->routing_files = $routing_files; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->environment = $environment; $this->context = new RequestContext(); } /** - * Find the list of routing files - * - * @param \phpbb\finder $finder - * @return router - */ - public function find_routing_files(\phpbb\finder $finder) + * Find the list of routing files + * + * @param array $paths Array of paths where to look for routing files. + * @return router + */ + public function find_routing_files(array $paths) { - if ($this->routing_files === null || empty($this->routing_files)) + $this->routing_files = array($this->phpbb_root_path . 'config/' . $this->environment . '/routing/environment.yml'); + foreach ($paths as $path) { - // We hardcode the path to the core config directory - // because the finder cannot find it - $this->routing_files = array_merge($this->routing_files, array('config/routing.yml'), array_keys($finder - ->directory('/config') - ->suffix('routing.yml') - ->find() - )); + if (file_exists($path . 'config/' . $this->environment . '/routing/environment.yml')) + { + $this->routing_files[] = $path . 'config/' . $this->environment . '/routing/environment.yml'; + } + else if (!is_dir($path . 'config/' . $this->environment)) + { + if (file_exists($path . 'config/default/routing/environment.yml')) + { + $this->routing_files[] = $path . 'config/default/routing/environment.yml'; + } + else if (!is_dir($path . 'config/default/routing') && file_exists($path . 'config/routing.yml')) + { + $this->routing_files[] = $path . 'config/routing.yml'; + } + } } return $this; } /** - * Find a list of controllers - * - * @param string $base_path Base path to prepend to file paths - * @return router - */ + * Find a list of controllers + * + * @param string $base_path Base path to prepend to file paths + * @return router + */ public function find($base_path = '') { if ($this->route_collection === null || $this->route_collection->count() === 0) @@ -130,15 +156,15 @@ class router implements RouterInterface } /** - * Get the list of routes - * - * @return RouteCollection Get the route collection - */ + * Get the list of routes + * + * @return RouteCollection Get the route collection + */ public function get_routes() { if ($this->route_collection == null || empty($this->routing_files)) { - $this->find_routing_files($this->extension_manager->get_finder()) + $this->find_routing_files($this->extension_manager->all_enabled()) ->find($this->phpbb_root_path); } @@ -146,16 +172,16 @@ class router implements RouterInterface } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function getRouteCollection() { return $this->get_routes(); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function setContext(RequestContext $context) { $this->context = $context; @@ -171,34 +197,34 @@ class router implements RouterInterface } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function getContext() { return $this->context; } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { return $this->get_generator()->generate($name, $parameters, $referenceType); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function match($pathinfo) { return $this->get_matcher()->match($pathinfo); } /** - * Gets the UrlMatcher instance associated with this Router. - * - * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface A UrlMatcherInterface instance - */ + * Gets the UrlMatcher instance associated with this Router. + * + * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface A UrlMatcherInterface instance + */ public function get_matcher() { if ($this->matcher !== null) @@ -218,8 +244,8 @@ class router implements RouterInterface return $this->matcher; } /** - * Creates a new dumped URL Matcher (dump it if necessary) - */ + * Creates a new dumped URL Matcher (dump it if necessary) + */ protected function create_dumped_url_matcher() { if (!file_exists($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext)) @@ -240,18 +266,18 @@ class router implements RouterInterface } /** - * Creates a new URL Matcher - */ + * Creates a new URL Matcher + */ protected function create_new_url_matcher() { $this->matcher = new UrlMatcher($this->get_routes(), $this->context); } /** - * Gets the UrlGenerator instance associated with this Router. - * - * @return \Symfony\Component\Routing\Generator\UrlGeneratorInterface A UrlGeneratorInterface instance - */ + * Gets the UrlGenerator instance associated with this Router. + * + * @return \Symfony\Component\Routing\Generator\UrlGeneratorInterface A UrlGeneratorInterface instance + */ public function get_generator() { if ($this->generator !== null) @@ -272,8 +298,8 @@ class router implements RouterInterface } /** - * Creates a new dumped URL Generator (dump it if necessary) - */ + * Creates a new dumped URL Generator (dump it if necessary) + */ protected function create_dumped_url_generator() { if (!file_exists($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext)) @@ -294,8 +320,8 @@ class router implements RouterInterface } /** - * Creates a new URL Generator - */ + * Creates a new URL Generator + */ protected function create_new_url_generator() { $this->generator = new UrlGenerator($this->get_routes(), $this->context); diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php index 0bf30b8a91..067bb3ef97 100644 --- a/tests/avatar/driver/barfoo.php +++ b/tests/avatar/driver/barfoo.php @@ -1,26 +1,26 @@ -<?php
-
-namespace phpbb\avatar\driver;
-
-class barfoo extends \phpbb\avatar\driver\driver
-{
- public function get_data($row)
- {
- return array();
- }
-
- public function prepare_form($request, $template, $user, $row, &$error)
- {
- return false;
- }
-
- public function process_form($request, $template, $user, $row, &$error)
- {
- return false;
- }
-
- public function get_template_name()
- {
- return 'barfoo.html';
- }
-}
+<?php + +namespace phpbb\avatar\driver; + +class barfoo extends \phpbb\avatar\driver\driver +{ + public function get_data($row) + { + return array(); + } + + public function prepare_form($request, $template, $user, $row, &$error) + { + return false; + } + + public function process_form($request, $template, $user, $row, &$error) + { + return false; + } + + public function get_template_name() + { + return 'barfoo.html'; + } +} diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index aabdaf5ac4..16d50ccad4 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -1,26 +1,26 @@ -<?php
-
-namespace phpbb\avatar\driver;
-
-class foobar extends \phpbb\avatar\driver\driver
-{
- public function get_data($row)
- {
- return array();
- }
-
- public function prepare_form($request, $template, $user, $row, &$error)
- {
- return false;
- }
-
- public function process_form($request, $template, $user, $row, &$error)
- {
- return false;
- }
-
- public function get_template_name()
- {
- return 'foobar.html';
- }
-}
+<?php + +namespace phpbb\avatar\driver; + +class foobar extends \phpbb\avatar\driver\driver +{ + public function get_data($row) + { + return array(); + } + + public function prepare_form($request, $template, $user, $row, &$error) + { + return false; + } + + public function process_form($request, $template, $user, $row, &$error) + { + return false; + } + + public function get_template_name() + { + return 'foobar.html'; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0e81f4372a..ace48ea035 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,6 +12,8 @@ */ define('IN_PHPBB', true); +define('PHPBB_ENVIRONMENT', 'test'); + $phpbb_root_path = 'phpBB/'; $phpEx = 'php'; require_once $phpbb_root_path . 'includes/startup.php'; diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 028a73d70d..19d40cf071 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -113,14 +113,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case ) ); - $finder = new \phpbb\finder( - new \phpbb\filesystem(), - dirname(__FILE__) . '/', - new phpbb_mock_cache() - ); - $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); - $this->router = new phpbb_mock_router($this->extension_manager, dirname(__FILE__) . '/', 'php'); - $this->router->find_routing_files($finder); + $this->router = new phpbb_mock_router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); + $this->router->find_routing_files($this->extension_manager->all_enabled()); $this->router->find(dirname(__FILE__) . '/'); // Set correct current phpBB root path $this->root_path = $this->get_phpbb_root_path(); @@ -325,7 +319,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } -//TODO + public function helper_url_data_absolute_with_rewrite() { return array( diff --git a/tests/controller/config/routing.yml b/tests/controller/config/test/routing/environment.yml index 175b11f130..175b11f130 100644 --- a/tests/controller/config/routing.yml +++ b/tests/controller/config/test/routing/environment.yml diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index cd90dda751..354a902831 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -30,13 +30,18 @@ class phpbb_controller_controller_test extends phpbb_test_case 'ext_active' => '1', 'ext_path' => 'ext/vendor2/foo/', ), + 'vendor2/bar' => array( + 'ext_name' => 'vendor2/bar', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor2/bar/', + ), )); } public function test_router_find_files() { - $router = new \phpbb\routing\router($this->extension_manager, dirname(__FILE__) . '/', 'php'); - $router->find_routing_files($this->extension_manager->get_finder()); + $router = new \phpbb\routing\router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); + $router->find_routing_files($this->extension_manager->all_enabled()); $routes = $router->find(__DIR__)->get_routes(); // This will need to be updated if any new routes are defined @@ -49,6 +54,9 @@ class phpbb_controller_controller_test extends phpbb_test_case $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2')); $this->assertEquals('/foo/bar', $routes->get('controller2')->getPath()); + $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller3')); + $this->assertEquals('/bar', $routes->get('controller3')->getPath()); + $this->assertNull($routes->get('controller_noroute')); } diff --git a/tests/controller/ext/vendor2/bar/config/services.yml b/tests/controller/ext/vendor2/bar/config/services.yml new file mode 100644 index 0000000000..05a8a1994d --- /dev/null +++ b/tests/controller/ext/vendor2/bar/config/services.yml @@ -0,0 +1,3 @@ +services: + bar.controller: + class: bar\controller diff --git a/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml new file mode 100644 index 0000000000..85c93b453f --- /dev/null +++ b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml @@ -0,0 +1,3 @@ +controller3: + pattern: /bar + defaults: { _controller: bar.controller:handle } diff --git a/tests/controller/ext/vendor2/bar/controller.php b/tests/controller/ext/vendor2/bar/controller.php new file mode 100644 index 0000000000..ad35f5a051 --- /dev/null +++ b/tests/controller/ext/vendor2/bar/controller.php @@ -0,0 +1,18 @@ +<?php + +namespace bar; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ + /** + * Handle method + * + * @return null + */ + public function handle() + { + return new Response('Test', 200); + } +} diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 4ae6017989..d52fb6b085 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -14,6 +14,7 @@ namespace { require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + require_once dirname(__FILE__) . '/fixtures/ext/vendor/enabled_4/di/extension.php'; class phpbb_di_container_test extends \phpbb_test_case { @@ -57,6 +58,9 @@ namespace // Checks use_extensions $this->assertTrue($container->hasParameter('enabled')); + $this->assertTrue($container->hasParameter('enabled_2')); + $this->assertTrue($container->hasParameter('enabled_3')); + $this->assertTrue($container->hasParameter('enabled_4')); $this->assertFalse($container->hasParameter('disabled')); $this->assertFalse($container->hasParameter('available')); @@ -142,7 +146,6 @@ namespace $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->hasParameter('my_parameter')); - $this->assertFalse($container->hasParameter('core.root_path')); } } } @@ -199,6 +202,9 @@ namespace phpbb\db\driver { return array( array('ext_name' => 'vendor/enabled'), + array('ext_name' => 'vendor/enabled-2'), + array('ext_name' => 'vendor/enabled-3'), + array('ext_name' => 'vendor/enabled_4'), ); } } diff --git a/tests/di/fixtures/config/test/config.yml b/tests/di/fixtures/config/test/config.yml new file mode 100644 index 0000000000..fcfa84f68b --- /dev/null +++ b/tests/di/fixtures/config/test/config.yml @@ -0,0 +1,2 @@ +core: + require_dev_dependencies: true diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/test/container/environment.yml index f2a22ae109..f2a22ae109 100644 --- a/tests/di/fixtures/config/services.yml +++ b/tests/di/fixtures/config/test/container/environment.yml diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml index 31ada384bf..31ada384bf 100644 --- a/tests/di/fixtures/ext/vendor/disabled/config/services.yml +++ b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml diff --git a/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml new file mode 100644 index 0000000000..feeb5a7a2d --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml @@ -0,0 +1,2 @@ +parameters: + enabled_2: true diff --git a/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml new file mode 100644 index 0000000000..0dae35d2bd --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml @@ -0,0 +1,2 @@ +parameters: + enabled_3: true diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml index 88a7919ed1..88a7919ed1 100644 --- a/tests/di/fixtures/ext/vendor/enabled/config/services.yml +++ b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml diff --git a/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php new file mode 100644 index 0000000000..8342625687 --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php @@ -0,0 +1,31 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace vendor\enabled_4\di; + +use phpbb\extension\di\extension_base; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +/** +* Container core extension +*/ +class extension extends extension_base +{ + protected function load_services(ContainerBuilder $container) + { + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->ext_path))); + $loader->load('environment.yml'); + } +} diff --git a/tests/di/fixtures/ext/vendor/enabled_4/environment.yml b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml new file mode 100644 index 0000000000..d0affe4fd6 --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml @@ -0,0 +1,2 @@ +parameters: + enabled_4: true diff --git a/tests/di/fixtures/other_config/test/config.yml b/tests/di/fixtures/other_config/test/config.yml new file mode 100644 index 0000000000..fcfa84f68b --- /dev/null +++ b/tests/di/fixtures/other_config/test/config.yml @@ -0,0 +1,2 @@ +core: + require_dev_dependencies: true diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/test/container/environment.yml index c299bfc648..c299bfc648 100644 --- a/tests/di/fixtures/other_config/services.yml +++ b/tests/di/fixtures/other_config/test/container/environment.yml diff --git a/tests/pagination/config/routing.yml b/tests/pagination/config/test/routing/environment.yml index dd667274cd..dd667274cd 100644 --- a/tests/pagination/config/routing.yml +++ b/tests/pagination/config/test/routing/environment.yml diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 04f7b807a7..1b9e8c751c 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -36,16 +36,10 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case $filesystem = new \phpbb\filesystem(); $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); - $finder = new \phpbb\finder( - $filesystem, - dirname(__FILE__) . '/', - new phpbb_mock_cache() - ); - $finder->set_extensions(array_keys($manager->all_enabled())); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $router = new phpbb_mock_router($manager, dirname(__FILE__) . '/', 'php'); - $router->find_routing_files($finder); + $router = new phpbb_mock_router($manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); + $router->find_routing_files($manager->all_enabled()); $router->find(dirname(__FILE__) . '/'); $request = new phpbb_mock_request(); diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 3e25286480..505eb7006f 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -96,6 +96,7 @@ class phpbb_session_testable_factory 'auth.provider.db', new phpbb_mock_auth_provider() ); + $phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT); $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config); $provider_collection->add('auth.provider.db'); $phpbb_container->set( diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cdb3d01524..9391795e32 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -204,6 +204,11 @@ class phpbb_functional_test_case extends phpbb_test_case { if (!$this->cache) { + global $phpbb_container; + + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT); + $this->cache = new \phpbb\cache\driver\file; } |