mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-03 07:18:08 +02:00
Merge pull request #2883 from Nicofuma/ticket/12620
[ticket/12620] Allow the user to define multiples environments
This commit is contained in:
@@ -283,6 +283,8 @@
|
|||||||
<delete file="${dir}/config.php" />
|
<delete file="${dir}/config.php" />
|
||||||
<delete dir="${dir}/develop" />
|
<delete dir="${dir}/develop" />
|
||||||
<delete dir="${dir}/install/data" />
|
<delete dir="${dir}/install/data" />
|
||||||
|
<delete dir="${dir}/config/development" />
|
||||||
|
<delete dir="${dir}/config/test" />
|
||||||
|
|
||||||
<phingcall target="clean-vendor-dir">
|
<phingcall target="clean-vendor-dir">
|
||||||
<property name="dir" value="${dir}" />
|
<property name="dir" value="${dir}" />
|
||||||
|
@@ -21,7 +21,6 @@ define('IN_PHPBB', true);
|
|||||||
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
||||||
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
||||||
include($phpbb_root_path . 'common.' . $phpEx);
|
include($phpbb_root_path . 'common.' . $phpEx);
|
||||||
include($phpbb_root_path . 'includes/functions_url_matcher.' . $phpEx);
|
|
||||||
|
|
||||||
// Start session management
|
// Start session management
|
||||||
$user->session_begin();
|
$user->session_begin();
|
||||||
|
@@ -21,6 +21,12 @@ if (php_sapi_name() != 'cli')
|
|||||||
}
|
}
|
||||||
|
|
||||||
define('IN_PHPBB', true);
|
define('IN_PHPBB', true);
|
||||||
|
|
||||||
|
if (!defined('PHPBB_ENVIRONMENT'))
|
||||||
|
{
|
||||||
|
@define('PHPBB_ENVIRONMENT', 'production');
|
||||||
|
}
|
||||||
|
|
||||||
$phpbb_root_path = __DIR__ . '/../';
|
$phpbb_root_path = __DIR__ . '/../';
|
||||||
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
||||||
require($phpbb_root_path . 'includes/startup.' . $phpEx);
|
require($phpbb_root_path . 'includes/startup.' . $phpEx);
|
||||||
|
@@ -29,6 +29,11 @@ $phpbb_class_loader->register();
|
|||||||
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
||||||
extract($phpbb_config_php_file->get_all());
|
extract($phpbb_config_php_file->get_all());
|
||||||
|
|
||||||
|
if (!defined('PHPBB_ENVIRONMENT'))
|
||||||
|
{
|
||||||
|
@define('PHPBB_ENVIRONMENT', 'production');
|
||||||
|
}
|
||||||
|
|
||||||
if (!defined('PHPBB_INSTALLED'))
|
if (!defined('PHPBB_INSTALLED'))
|
||||||
{
|
{
|
||||||
// Redirect the user to the installer
|
// Redirect the user to the installer
|
||||||
@@ -94,8 +99,18 @@ $phpbb_class_loader_ext->register();
|
|||||||
phpbb_load_extensions_autoloaders($phpbb_root_path);
|
phpbb_load_extensions_autoloaders($phpbb_root_path);
|
||||||
|
|
||||||
// Set up container
|
// Set up container
|
||||||
$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx);
|
try
|
||||||
$phpbb_container = $phpbb_container_builder->get_container();
|
{
|
||||||
|
$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->set_cache($phpbb_container->get('cache.driver'));
|
||||||
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
|
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
|
||||||
|
0
phpBB/config/default/config.yml
Normal file
0
phpBB/config/default/config.yml
Normal file
@@ -1,19 +1,19 @@
|
|||||||
imports:
|
imports:
|
||||||
- { resource: auth.yml }
|
- { resource: services_auth.yml }
|
||||||
- { resource: avatar.yml }
|
- { resource: services_avatar.yml }
|
||||||
- { resource: captcha.yml }
|
- { resource: services_captcha.yml }
|
||||||
- { resource: console.yml }
|
- { resource: services_console.yml }
|
||||||
- { resource: content.yml }
|
- { resource: services_content.yml }
|
||||||
- { resource: cron.yml }
|
- { resource: services_cron.yml }
|
||||||
- { resource: db.yml }
|
- { resource: services_db.yml }
|
||||||
- { resource: event.yml }
|
- { resource: services_event.yml }
|
||||||
- { resource: feed.yml }
|
- { resource: services_feed.yml }
|
||||||
- { resource: mimetype_guesser.yml }
|
- { resource: services_mimetype_guesser.yml }
|
||||||
- { resource: notification.yml }
|
- { resource: services_notification.yml }
|
||||||
- { resource: password.yml }
|
- { resource: services_password.yml }
|
||||||
- { resource: profilefield.yml }
|
- { resource: services_profilefield.yml }
|
||||||
- { resource: twig.yml }
|
- { resource: services_twig.yml }
|
||||||
- { resource: user.yml }
|
- { resource: services_user.yml }
|
||||||
|
|
||||||
- { resource: tables.yml }
|
- { resource: tables.yml }
|
||||||
- { resource: parameters.yml }
|
- { resource: parameters.yml }
|
||||||
@@ -157,6 +157,7 @@ services:
|
|||||||
- @ext.manager
|
- @ext.manager
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
- %core.php_ext%
|
- %core.php_ext%
|
||||||
|
- %core.environment%
|
||||||
|
|
||||||
router.listener:
|
router.listener:
|
||||||
class: Symfony\Component\HttpKernel\EventListener\RouterListener
|
class: Symfony\Component\HttpKernel\EventListener\RouterListener
|
60
phpBB/config/default/container/services_migrator.yml
Normal file
60
phpBB/config/default/container/services_migrator.yml
Normal file
@@ -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 }
|
@@ -1,5 +1,5 @@
|
|||||||
parameters:
|
parameters:
|
||||||
core.template.cache_path: %core.root_path%cache/twig/
|
core.template.cache_path: %core.root_path%cache/%core.environment%/twig/
|
||||||
|
|
||||||
services:
|
services:
|
||||||
template.twig.environment:
|
template.twig.environment:
|
5
phpBB/config/development/config.yml
Normal file
5
phpBB/config/development/config.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../default/config.yml }
|
||||||
|
|
||||||
|
core:
|
||||||
|
require_dev_dependencies: true
|
3
phpBB/config/development/container/environment.yml
Normal file
3
phpBB/config/development/container/environment.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: services.yml }
|
||||||
|
- { resource: parameters.yml }
|
2
phpBB/config/development/container/parameters.yml
Normal file
2
phpBB/config/development/container/parameters.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/parameters.yml }
|
2
phpBB/config/development/container/services.yml
Normal file
2
phpBB/config/development/container/services.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/services.yml }
|
2
phpBB/config/development/routing/environment.yml
Normal file
2
phpBB/config/development/routing/environment.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
core.default:
|
||||||
|
resource: "../../default/routing/routing.yml"
|
2
phpBB/config/production/config.yml
Normal file
2
phpBB/config/production/config.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../default/config.yml }
|
3
phpBB/config/production/container/environment.yml
Normal file
3
phpBB/config/production/container/environment.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: services.yml }
|
||||||
|
- { resource: parameters.yml }
|
2
phpBB/config/production/container/parameters.yml
Normal file
2
phpBB/config/production/container/parameters.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/parameters.yml }
|
2
phpBB/config/production/container/services.yml
Normal file
2
phpBB/config/production/container/services.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/services.yml }
|
2
phpBB/config/production/routing/environment.yml
Normal file
2
phpBB/config/production/routing/environment.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
core.default:
|
||||||
|
resource: "../../default/routing/routing.yml"
|
5
phpBB/config/test/config.yml
Normal file
5
phpBB/config/test/config.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../default/config.yml }
|
||||||
|
|
||||||
|
core:
|
||||||
|
require_dev_dependencies: true
|
3
phpBB/config/test/container/environment.yml
Normal file
3
phpBB/config/test/container/environment.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: services.yml }
|
||||||
|
- { resource: parameters.yml }
|
2
phpBB/config/test/container/parameters.yml
Normal file
2
phpBB/config/test/container/parameters.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/parameters.yml }
|
2
phpBB/config/test/container/services.yml
Normal file
2
phpBB/config/test/container/services.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports:
|
||||||
|
- { resource: ../../default/container/services.yml }
|
2
phpBB/config/test/routing/environment.yml
Normal file
2
phpBB/config/test/routing/environment.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
core.default:
|
||||||
|
resource: "../../default/routing/routing.yml"
|
@@ -42,6 +42,11 @@ if (isset($_GET['avatar']))
|
|||||||
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
||||||
extract($phpbb_config_php_file->get_all());
|
extract($phpbb_config_php_file->get_all());
|
||||||
|
|
||||||
|
if (!defined('PHPBB_ENVIRONMENT'))
|
||||||
|
{
|
||||||
|
@define('PHPBB_ENVIRONMENT', 'production');
|
||||||
|
}
|
||||||
|
|
||||||
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
|
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
|
||||||
{
|
{
|
||||||
exit;
|
exit;
|
||||||
|
@@ -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 .= "\n@define('PHPBB_INSTALLED', true);\n";
|
||||||
$config_data .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n";
|
$config_data .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n";
|
||||||
|
|
||||||
if ($debug)
|
if ($debug_test)
|
||||||
{
|
{
|
||||||
$config_data .= "@define('DEBUG', true);\n";
|
$config_data .= "@define('PHPBB_ENVIRONMENT', 'test');\n";
|
||||||
|
}
|
||||||
|
else if ($debug)
|
||||||
|
{
|
||||||
|
$config_data .= "@define('PHPBB_ENVIRONMENT', 'development');\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$config_data .= "// @define('DEBUG', true);\n";
|
$config_data .= "@define('PHPBB_ENVIRONMENT', 'production');\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($debug_container)
|
if ($debug_container)
|
||||||
@@ -472,6 +476,7 @@ function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_cont
|
|||||||
if ($debug_test)
|
if ($debug_test)
|
||||||
{
|
{
|
||||||
$config_data .= "@define('DEBUG_TEST', true);\n";
|
$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;
|
return $config_data;
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
define('IN_PHPBB', true);
|
define('IN_PHPBB', true);
|
||||||
define('IN_INSTALL', true);
|
define('IN_INSTALL', true);
|
||||||
|
define('PHPBB_ENVIRONMENT', 'production');
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
|
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
|
||||||
|
10
phpBB/phpbb/cache/driver/file.php
vendored
10
phpBB/phpbb/cache/driver/file.php
vendored
@@ -27,8 +27,14 @@ class file extends \phpbb\cache\driver\base
|
|||||||
*/
|
*/
|
||||||
function __construct($cache_dir = null)
|
function __construct($cache_dir = null)
|
||||||
{
|
{
|
||||||
global $phpbb_root_path;
|
global $phpbb_root_path, $phpbb_container;
|
||||||
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/';
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -41,7 +41,8 @@ class helper
|
|||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \phpbb\routing\router phpBB router
|
* phpBB router
|
||||||
|
* @var \phpbb\routing\router
|
||||||
*/
|
*/
|
||||||
protected $router;
|
protected $router;
|
||||||
|
|
||||||
|
@@ -13,16 +13,25 @@
|
|||||||
|
|
||||||
namespace phpbb\di;
|
namespace phpbb\di;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\ConfigCache;
|
||||||
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
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
|
class container_builder
|
||||||
{
|
{
|
||||||
/** @var string phpBB Root Path */
|
/**
|
||||||
|
* @var string phpBB Root Path
|
||||||
|
*/
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
/** @var string php file extension */
|
/**
|
||||||
|
* @var string php file extension
|
||||||
|
*/
|
||||||
protected $php_ext;
|
protected $php_ext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,6 +120,11 @@ class container_builder
|
|||||||
*/
|
*/
|
||||||
protected $config_php_file;
|
protected $config_php_file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $cache_dir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -133,23 +147,30 @@ class container_builder
|
|||||||
public function get_container()
|
public function get_container()
|
||||||
{
|
{
|
||||||
$container_filename = $this->get_container_filename();
|
$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);
|
require($container_filename);
|
||||||
$this->container = new \phpbb_cache_container();
|
$this->container = new \phpbb_cache_container();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($this->config_path === null)
|
$container_extensions = array(new \phpbb\di\extension\core($this->get_config_path()));
|
||||||
{
|
|
||||||
$this->config_path = $this->phpbb_root_path . 'config';
|
|
||||||
}
|
|
||||||
$container_extensions = array(new \phpbb\di\extension\core($this->config_path));
|
|
||||||
|
|
||||||
if ($this->use_extensions)
|
if ($this->use_extensions)
|
||||||
{
|
{
|
||||||
$installed_exts = $this->get_installed_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)
|
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();
|
$this->inject_custom_parameters();
|
||||||
|
|
||||||
if ($this->compile_container)
|
if ($this->compile_container)
|
||||||
@@ -178,9 +202,9 @@ class container_builder
|
|||||||
$this->container->compile();
|
$this->container->compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dump_container && !defined('DEBUG_CONTAINER'))
|
if ($this->dump_container)
|
||||||
{
|
{
|
||||||
$this->dump_container($container_filename);
|
$this->dump_container($config_cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +290,16 @@ class container_builder
|
|||||||
$this->config_path = $config_path;
|
$this->config_path = $config_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Set custom parameters to inject into the container.
|
||||||
*
|
*
|
||||||
@@ -276,12 +310,32 @@ class container_builder
|
|||||||
$this->custom_parameters = $custom_parameters;
|
$this->custom_parameters = $custom_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* 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);
|
$dumper = new PhpDumper($this->container);
|
||||||
$cached_container_dump = $dumper->dump(array(
|
$cached_container_dump = $dumper->dump(array(
|
||||||
@@ -289,7 +343,7 @@ class container_builder
|
|||||||
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
||||||
));
|
));
|
||||||
|
|
||||||
file_put_contents($container_filename, $cached_container_dump);
|
$cache->write($cached_container_dump, $this->container->getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,14 +416,19 @@ class container_builder
|
|||||||
*/
|
*/
|
||||||
protected function create_container(array $extensions)
|
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)
|
foreach ($extensions as $extension)
|
||||||
{
|
{
|
||||||
$container->registerExtension($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;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,19 +437,53 @@ class container_builder
|
|||||||
*/
|
*/
|
||||||
protected function inject_custom_parameters()
|
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)
|
foreach ($this->custom_parameters as $key => $value)
|
||||||
{
|
{
|
||||||
$this->container->setParameter($key, $value);
|
$this->container->setParameter($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)
|
||||||
|
{
|
||||||
|
if (0 === strpos($key, 'PHPBB__'))
|
||||||
|
{
|
||||||
|
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parameters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the filename under which the dumped container will be stored.
|
* Get the filename under which the dumped container will be stored.
|
||||||
@@ -400,6 +493,16 @@ class container_builder
|
|||||||
protected function get_container_filename()
|
protected function get_container_filename()
|
||||||
{
|
{
|
||||||
$filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
phpBB/phpbb/di/extension/container_configuration.php
Normal file
38
phpBB/phpbb/di/extension/container_configuration.php
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -13,10 +13,11 @@
|
|||||||
|
|
||||||
namespace phpbb\di\extension;
|
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;
|
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
|
* Container core extension
|
||||||
@@ -42,15 +43,41 @@ class core extends Extension
|
|||||||
/**
|
/**
|
||||||
* Loads a specific configuration.
|
* Loads a specific configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration values
|
* @param array $configs An array of configuration values
|
||||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
||||||
*/
|
*/
|
||||||
public function load(array $config, ContainerBuilder $container)
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path)));
|
$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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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';
|
|
||||||
}
|
|
||||||
}
|
|
137
phpBB/phpbb/extension/di/extension_base.php
Normal file
137
phpBB/phpbb/extension/di/extension_base.php
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,27 +25,42 @@ use Symfony\Component\Config\FileLocator;
|
|||||||
use phpbb\extension\manager;
|
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
|
class router implements RouterInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var manager Extension manager
|
* Extension manager
|
||||||
|
*
|
||||||
|
* @var manager
|
||||||
*/
|
*/
|
||||||
protected $extension_manager;
|
protected $extension_manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string phpBB root path
|
* phpBB root path
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string PHP file extensions
|
* PHP file extensions
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $php_ext;
|
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;
|
protected $routing_files;
|
||||||
|
|
||||||
@@ -72,37 +87,48 @@ class router implements RouterInterface
|
|||||||
/**
|
/**
|
||||||
* Construct method
|
* Construct method
|
||||||
*
|
*
|
||||||
* @param manager $extension_manager The extension manager
|
* @param manager $extension_manager Extension manager
|
||||||
* @param string $phpbb_root_path phpBB root path
|
* @param string $phpbb_root_path phpBB root path
|
||||||
* @param string $php_ext PHP file extension
|
* @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
|
* @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())
|
public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array())
|
||||||
{
|
{
|
||||||
$this->extension_manager = $extension_manager;
|
$this->extension_manager = $extension_manager;
|
||||||
$this->routing_files = $routing_files;
|
$this->routing_files = $routing_files;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
|
$this->environment = $environment;
|
||||||
$this->context = new RequestContext();
|
$this->context = new RequestContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the list of routing files
|
* Find the list of routing files
|
||||||
*
|
*
|
||||||
* @param \phpbb\finder $finder
|
* @param array $paths Array of paths where to look for routing files.
|
||||||
* @return router
|
* @return router
|
||||||
*/
|
*/
|
||||||
public function find_routing_files(\phpbb\finder $finder)
|
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
|
if (file_exists($path . 'config/' . $this->environment . '/routing/environment.yml'))
|
||||||
// because the finder cannot find it
|
{
|
||||||
$this->routing_files = array_merge($this->routing_files, array('config/routing.yml'), array_keys($finder
|
$this->routing_files[] = $path . 'config/' . $this->environment . '/routing/environment.yml';
|
||||||
->directory('/config')
|
}
|
||||||
->suffix('routing.yml')
|
else if (!is_dir($path . 'config/' . $this->environment))
|
||||||
->find()
|
{
|
||||||
));
|
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;
|
return $this;
|
||||||
@@ -138,7 +164,7 @@ class router implements RouterInterface
|
|||||||
{
|
{
|
||||||
if ($this->route_collection == null || empty($this->routing_files))
|
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);
|
->find($this->phpbb_root_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
define('IN_PHPBB', true);
|
define('IN_PHPBB', true);
|
||||||
|
define('PHPBB_ENVIRONMENT', 'test');
|
||||||
|
|
||||||
$phpbb_root_path = 'phpBB/';
|
$phpbb_root_path = 'phpBB/';
|
||||||
$phpEx = 'php';
|
$phpEx = 'php';
|
||||||
require_once $phpbb_root_path . 'includes/startup.php';
|
require_once $phpbb_root_path . 'includes/startup.php';
|
||||||
|
@@ -113,14 +113,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$finder = new \phpbb\finder(
|
$this->router = new phpbb_mock_router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT);
|
||||||
new \phpbb\filesystem(),
|
$this->router->find_routing_files($this->extension_manager->all_enabled());
|
||||||
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->find(dirname(__FILE__) . '/');
|
$this->router->find(dirname(__FILE__) . '/');
|
||||||
// Set correct current phpBB root path
|
// Set correct current phpBB root path
|
||||||
$this->root_path = $this->get_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->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);
|
$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()
|
public function helper_url_data_absolute_with_rewrite()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
@@ -30,13 +30,18 @@ class phpbb_controller_controller_test extends phpbb_test_case
|
|||||||
'ext_active' => '1',
|
'ext_active' => '1',
|
||||||
'ext_path' => 'ext/vendor2/foo/',
|
'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()
|
public function test_router_find_files()
|
||||||
{
|
{
|
||||||
$router = new \phpbb\routing\router($this->extension_manager, dirname(__FILE__) . '/', 'php');
|
$router = new \phpbb\routing\router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT);
|
||||||
$router->find_routing_files($this->extension_manager->get_finder());
|
$router->find_routing_files($this->extension_manager->all_enabled());
|
||||||
$routes = $router->find(__DIR__)->get_routes();
|
$routes = $router->find(__DIR__)->get_routes();
|
||||||
|
|
||||||
// This will need to be updated if any new routes are defined
|
// 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->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2'));
|
||||||
$this->assertEquals('/foo/bar', $routes->get('controller2')->getPath());
|
$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'));
|
$this->assertNull($routes->get('controller_noroute'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
tests/controller/ext/vendor2/bar/config/services.yml
Normal file
3
tests/controller/ext/vendor2/bar/config/services.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
services:
|
||||||
|
bar.controller:
|
||||||
|
class: bar\controller
|
@@ -0,0 +1,3 @@
|
|||||||
|
controller3:
|
||||||
|
pattern: /bar
|
||||||
|
defaults: { _controller: bar.controller:handle }
|
18
tests/controller/ext/vendor2/bar/controller.php
Normal file
18
tests/controller/ext/vendor2/bar/controller.php
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -14,6 +14,7 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
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
|
class phpbb_di_container_test extends \phpbb_test_case
|
||||||
{
|
{
|
||||||
@@ -57,6 +58,9 @@ namespace
|
|||||||
|
|
||||||
// Checks use_extensions
|
// Checks use_extensions
|
||||||
$this->assertTrue($container->hasParameter('enabled'));
|
$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('disabled'));
|
||||||
$this->assertFalse($container->hasParameter('available'));
|
$this->assertFalse($container->hasParameter('available'));
|
||||||
|
|
||||||
@@ -142,7 +146,6 @@ namespace
|
|||||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
||||||
|
|
||||||
$this->assertTrue($container->hasParameter('my_parameter'));
|
$this->assertTrue($container->hasParameter('my_parameter'));
|
||||||
$this->assertFalse($container->hasParameter('core.root_path'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +202,9 @@ namespace phpbb\db\driver
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('ext_name' => 'vendor/enabled'),
|
array('ext_name' => 'vendor/enabled'),
|
||||||
|
array('ext_name' => 'vendor/enabled-2'),
|
||||||
|
array('ext_name' => 'vendor/enabled-3'),
|
||||||
|
array('ext_name' => 'vendor/enabled_4'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
tests/di/fixtures/config/test/config.yml
Normal file
2
tests/di/fixtures/config/test/config.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
core:
|
||||||
|
require_dev_dependencies: true
|
2
tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml
vendored
Normal file
2
tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
parameters:
|
||||||
|
enabled_2: true
|
2
tests/di/fixtures/ext/vendor/enabled-3/config/services.yml
vendored
Normal file
2
tests/di/fixtures/ext/vendor/enabled-3/config/services.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
parameters:
|
||||||
|
enabled_3: true
|
31
tests/di/fixtures/ext/vendor/enabled_4/di/extension.php
vendored
Normal file
31
tests/di/fixtures/ext/vendor/enabled_4/di/extension.php
vendored
Normal file
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
2
tests/di/fixtures/ext/vendor/enabled_4/environment.yml
vendored
Normal file
2
tests/di/fixtures/ext/vendor/enabled_4/environment.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
parameters:
|
||||||
|
enabled_4: true
|
2
tests/di/fixtures/other_config/test/config.yml
Normal file
2
tests/di/fixtures/other_config/test/config.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
core:
|
||||||
|
require_dev_dependencies: true
|
@@ -36,16 +36,10 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
|
|||||||
|
|
||||||
$filesystem = new \phpbb\filesystem();
|
$filesystem = new \phpbb\filesystem();
|
||||||
$manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array());
|
$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'));
|
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||||
$router = new phpbb_mock_router($manager, dirname(__FILE__) . '/', 'php');
|
$router = new phpbb_mock_router($manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT);
|
||||||
$router->find_routing_files($finder);
|
$router->find_routing_files($manager->all_enabled());
|
||||||
$router->find(dirname(__FILE__) . '/');
|
$router->find(dirname(__FILE__) . '/');
|
||||||
|
|
||||||
$request = new phpbb_mock_request();
|
$request = new phpbb_mock_request();
|
||||||
|
@@ -96,6 +96,7 @@ class phpbb_session_testable_factory
|
|||||||
'auth.provider.db',
|
'auth.provider.db',
|
||||||
new phpbb_mock_auth_provider()
|
new phpbb_mock_auth_provider()
|
||||||
);
|
);
|
||||||
|
$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT);
|
||||||
$provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
|
$provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
|
||||||
$provider_collection->add('auth.provider.db');
|
$provider_collection->add('auth.provider.db');
|
||||||
$phpbb_container->set(
|
$phpbb_container->set(
|
||||||
|
@@ -204,6 +204,11 @@ class phpbb_functional_test_case extends phpbb_test_case
|
|||||||
{
|
{
|
||||||
if (!$this->cache)
|
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;
|
$this->cache = new \phpbb\cache\driver\file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user