From 9308764fae9f007311186569c873b183b3a8e9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 1 Sep 2018 01:32:22 +0200 Subject: [PATCH 1/5] [ticket/12631] Add finder.not_use_cache PHPBB3-12631 --- phpBB/config/default/container/services.yml | 1 + .../default/container/services_extensions.yml | 2 +- .../default/container/services_finder.yml | 8 +++ phpBB/config/development/config.yml | 3 ++ .../container/services_install_database.yml | 1 + phpBB/develop/create_schema_files.php | 2 +- .../di/extension/container_configuration.php | 4 ++ phpBB/phpbb/di/extension/core.php | 5 ++ phpBB/phpbb/extension/base.php | 6 +-- phpBB/phpbb/extension/manager.php | 16 +++--- phpBB/phpbb/finder/factory.php | 53 +++++++++++++++++++ phpBB/phpbb/{ => finder}/finder.php | 30 ++++++----- .../task/create_schema_file.php | 11 +++- tests/dbal/migrator_test.php | 4 +- tests/extension/finder_test.php | 12 +++-- tests/extension/manager_test.php | 7 +-- tests/extension/metadata_manager_test.php | 3 +- tests/mock/container_builder.php | 1 + tests/mock/extension_manager.php | 2 +- .../phpbb_database_test_case.php | 2 +- ...phpbb_database_test_connection_manager.php | 2 +- .../phpbb_functional_test_case.php | 3 +- 22 files changed, 136 insertions(+), 42 deletions(-) create mode 100644 phpBB/config/default/container/services_finder.yml create mode 100644 phpBB/phpbb/finder/factory.php rename phpBB/phpbb/{ => finder}/finder.php (93%) diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 1d48ead588..ba78673211 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -12,6 +12,7 @@ imports: - { resource: services_feed.yml } - { resource: services_files.yml } - { resource: services_filesystem.yml } + - { resource: services_finder.yml } - { resource: services_help.yml } - { resource: services_http.yml } - { resource: services_language.yml } diff --git a/phpBB/config/default/container/services_extensions.yml b/phpBB/config/default/container/services_extensions.yml index 53e36f0fda..2c04716683 100644 --- a/phpBB/config/default/container/services_extensions.yml +++ b/phpBB/config/default/container/services_extensions.yml @@ -5,9 +5,9 @@ services: - '@service_container' - '@dbal.conn' - '@config' + - '@finder.factory' - '%tables.ext%' - '%core.root_path%' - - '%core.php_ext%' - '@cache' ext.composer.installer: diff --git a/phpBB/config/default/container/services_finder.yml b/phpBB/config/default/container/services_finder.yml new file mode 100644 index 0000000000..9937f35396 --- /dev/null +++ b/phpBB/config/default/container/services_finder.yml @@ -0,0 +1,8 @@ +services: + finder.factory: + class: phpbb\finder\factory + arguments: + - '@cache' + - '%finder.not_use_cache%' + - '%core.root_path%' + - '%core.php_ext%' diff --git a/phpBB/config/development/config.yml b/phpBB/config/development/config.yml index 0c28916e27..fb96e5251c 100644 --- a/phpBB/config/development/config.yml +++ b/phpBB/config/development/config.yml @@ -25,3 +25,6 @@ core: session: log_errors: true + + finder: + not_use_cache: true diff --git a/phpBB/config/installer/container/services_install_database.yml b/phpBB/config/installer/container/services_install_database.yml index 14baed7e79..5f10ff0373 100644 --- a/phpBB/config/installer/container/services_install_database.yml +++ b/phpBB/config/installer/container/services_install_database.yml @@ -8,6 +8,7 @@ services: - '%core.root_path%' - '%core.php_ext%' - '%tables%' + - '%finder.not_use_cache%' tags: - { name: install_database_install, order: 1 } diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index e057975ba9..912b681575 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -43,7 +43,7 @@ require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$finder = new \phpbb\finder($phpbb_root_path); +$finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); $classes = $finder->core_path('phpbb/') ->directory('/db/migration/data') ->get_classes(); diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index b3a726ad2a..4d23de22de 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -64,6 +64,10 @@ class container_configuration implements ConfigurationInterface ->children() ->booleanNode('force_sid')->defaultValue(false)->end() ->booleanNode('log_errors')->defaultValue(false)->end() + ->arrayNode('finder') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('not_use_cache')->defaultValue(false)->end() ->end() ->end() ->end() diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 65848cdadf..20f3501be7 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -117,6 +117,11 @@ class core extends Extension foreach ($config['session'] as $name => $value) { $container->setParameter('session.' . $name, $value); + + // Set the finder options + foreach ($config['finder'] as $name => $value) + { + $container->setParameter('finder.' . $name, $value); } } diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index c056ab8bb3..57a281fdae 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -23,7 +23,7 @@ class base implements \phpbb\extension\extension_interface /** @var ContainerInterface */ protected $container; - /** @var \phpbb\finder */ + /** @var \phpbb\finder\finder */ protected $extension_finder; /** @var \phpbb\db\migrator */ @@ -42,12 +42,12 @@ class base implements \phpbb\extension\extension_interface * Constructor * * @param ContainerInterface $container Container object - * @param \phpbb\finder $extension_finder + * @param \phpbb\finder\finder $extension_finder * @param \phpbb\db\migrator $migrator * @param string $extension_name Name of this extension (from ext.manager) * @param string $extension_path Relative path to this extension */ - public function __construct(ContainerInterface $container, \phpbb\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path) + public function __construct(ContainerInterface $container, \phpbb\finder\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path) { $this->container = $container; $this->extension_finder = $extension_finder; diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 48d0fb6c92..275043d7e8 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -15,6 +15,7 @@ namespace phpbb\extension; use phpbb\exception\runtime_exception; use phpbb\file_downloader; +use phpbb\finder\factory as finder_factory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -27,8 +28,8 @@ class manager protected $db; protected $config; + protected $finder_factory; protected $cache; - protected $php_ext; protected $extensions; protected $extension_table; protected $phpbb_root_path; @@ -42,20 +43,19 @@ class manager * @param \phpbb\config\config $config Config object * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension, defaults to php * @param \phpbb\cache\service|null $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\service $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, finder_factory $finder_factory, $extension_table, $phpbb_root_path, \phpbb\cache\service $cache = null, $cache_name = '_ext') { $this->cache = $cache; $this->cache_name = $cache_name; $this->config = $config; + $this->finder_factory = $finder_factory; $this->container = $container; $this->db = $db; $this->extension_table = $extension_table; $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; $this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; @@ -568,14 +568,15 @@ class manager } /** - * Instantiates a \phpbb\finder. + * Instantiates a \phpbb\finder\finder. * * @param bool $use_all_available Should we load all extensions, or just enabled ones - * @return \phpbb\finder An extension finder instance + * @return \phpbb\finder\finder An extension finder instance */ public function get_finder($use_all_available = false) { - $finder = new \phpbb\finder($this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); + $finder = $this->finder_factory->get($this->cache_name . '_finder'); + if ($use_all_available) { $finder->set_extensions(array_keys($this->all_available())); @@ -584,6 +585,7 @@ class manager { $finder->set_extensions(array_keys($this->all_enabled())); } + return $finder; } } diff --git a/phpBB/phpbb/finder/factory.php b/phpBB/phpbb/finder/factory.php new file mode 100644 index 0000000000..21b568b735 --- /dev/null +++ b/phpBB/phpbb/finder/factory.php @@ -0,0 +1,53 @@ + +* @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\finder; + +/** +* The finder provides a simple way to locate files in the core and a set of extensions +*/ +class factory +{ + protected $cache; + protected $not_use_cache; + protected $phpbb_root_path; + protected $php_ext; + + /** + * Creates a new finder instance with its dependencies + * + * @param string $phpbb_root_path Path to the phpbb root directory + * @param \phpbb\cache\service $cache A cache instance or null + * @param string $php_ext php file extension + * @param string $cache_name The name of the cache variable, defaults to + * _ext_finder + */ + public function __construct(/*\phpbb\cache\service */ $cache, $not_use_cache, $phpbb_root_path, $php_ext) + { + $this->cache = $cache; + $this->not_use_cache = $not_use_cache; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * The cache variable name used to store $this->cached_queries in $this->cache. + * + * Allows the use of multiple differently configured finders with the same cache. + * @var string + */ + public function get($cache_name = '_ext_finder') + { + return new finder($this->cache, $this->not_use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name); + } +} diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder/finder.php similarity index 93% rename from phpBB/phpbb/finder.php rename to phpBB/phpbb/finder/finder.php index 1815377a7d..80b98b5eff 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder/finder.php @@ -11,7 +11,7 @@ * */ -namespace phpbb; +namespace phpbb\finder; use phpbb\filesystem\helper as filesystem_helper; @@ -23,6 +23,7 @@ class finder protected $extensions; protected $phpbb_root_path; protected $cache; + protected $not_use_cache; protected $php_ext; /** @@ -55,10 +56,11 @@ class finder * @param string $cache_name The name of the cache variable, defaults to * _ext_finder */ - public function __construct($phpbb_root_path = '', \phpbb\cache\service $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') + public function __construct(/*\phpbb\cache\service */ $cache, $not_use_cache, $phpbb_root_path, $php_ext, $cache_name = '_ext_finder') { $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; + $this->not_use_cache = $not_use_cache; $this->php_ext = $php_ext; $this->cache_name = $cache_name; @@ -81,7 +83,7 @@ class finder * * @param array $extensions A list of extensions that should be searched as well * @param bool $replace_list Should the list be emptied before adding the extensions - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function set_extensions(array $extensions, $replace_list = true) { @@ -101,7 +103,7 @@ class finder * Sets a core path to be searched in addition to extensions * * @param string $core_path The path relative to phpbb_root_path - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function core_path($core_path) { @@ -117,7 +119,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $suffix A filename suffix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function suffix($suffix) { @@ -134,7 +136,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $extension_suffix A filename suffix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function extension_suffix($extension_suffix) { @@ -150,7 +152,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $core_suffix A filename suffix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function core_suffix($core_suffix) { @@ -162,7 +164,7 @@ class finder * Sets the prefix all files found in extensions and core must match * * @param string $prefix A filename prefix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function prefix($prefix) { @@ -175,7 +177,7 @@ class finder * Sets a prefix all files found in extensions must match * * @param string $extension_prefix A filename prefix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function extension_prefix($extension_prefix) { @@ -187,7 +189,7 @@ class finder * Sets a prefix all files found in the core path must match * * @param string $core_prefix A filename prefix - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function core_prefix($core_prefix) { @@ -202,7 +204,7 @@ class finder * the current directory. * * @param string $directory - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function directory($directory) { @@ -215,7 +217,7 @@ class finder * Sets a directory all files found in extensions must be contained in * * @param string $extension_directory - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function extension_directory($extension_directory) { @@ -227,7 +229,7 @@ class finder * Sets a directory all files found in the core path must be contained in * * @param string $core_directory - * @return \phpbb\finder This object for chaining calls + * @return \phpbb\finder\finder This object for chaining calls */ public function core_directory($core_directory) { @@ -424,7 +426,7 @@ class finder $this->query['is_dir'] = $is_dir; $query = md5(serialize($this->query) . serialize($extensions)); - if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) + if (!$this->not_use_cache && $cache && isset($this->cached_queries[$query])) { return $this->cached_queries[$query]; } diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php index 99febcbd18..1788271365 100644 --- a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php +++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php @@ -45,6 +45,11 @@ class create_schema_file extends \phpbb\install\task_base */ protected $php_ext; + /** + * @var string + */ + protected $not_use_cache; + /** * Constructor * @@ -58,7 +63,8 @@ class create_schema_file extends \phpbb\install\task_base \phpbb\install\helper\database $db_helper, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, - $php_ext) + $php_ext, + $not_use_cache) { $dbms = $db_helper->get_available_dbms($config->get('dbms')); $dbms = $dbms[$config->get('dbms')]['DRIVER']; @@ -78,6 +84,7 @@ class create_schema_file extends \phpbb\install\task_base $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->not_use_cache = $not_use_cache; parent::__construct(true); } @@ -117,7 +124,7 @@ class create_schema_file extends \phpbb\install\task_base include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); } - $finder = new \phpbb\finder($this->phpbb_root_path, null, $this->php_ext); + $finder = new \phpbb\finder\finder(null, true, $this->phpbb_root_path, $this->php_ext); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $factory = new \phpbb\db\tools\factory(); $db_tools = $factory->get($this->db, true); diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 71a3ba7ef4..e75b45522e 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -54,6 +54,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); + $finder_factory = $this->createMock('\phpbb\finder\factory'); + $tools = array( new \phpbb\db\migration\tool\config($this->config), ); @@ -80,9 +82,9 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, + $finder_factory, 'phpbb_ext', __DIR__ . '/../../phpBB/', - 'php', null ); } diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index e890fd10af..75d400269c 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -15,7 +15,7 @@ class phpbb_extension_finder_test extends phpbb_test_case { /** @var \phpbb\extension\manager */ protected $extension_manager; - /** @var \phpbb\finder */ + /** @var \phpbb\finder\finder */ protected $finder; protected function setUp(): void @@ -243,7 +243,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new \phpbb\finder(__DIR__ . '/', $cache, 'php', '_custom_cache_name'); + $finder = new \phpbb\finder\finder($cache, true, __DIR__ . '/', 'php', '_custom_cache_name'); $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $files = $finder->suffix('_class.php')->get_files(); @@ -282,13 +282,15 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $finder = new \phpbb\finder( - __DIR__ . '/', + $finder = new \phpbb\finder\finder( new phpbb_mock_cache(array( '_ext_finder' => array( md5(serialize($query)) => array('file_name' => 'extension'), ), - )) + )), + true, + __DIR__ . '/', + '_ext_finder' ); $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index e984bf8957..14b6a9c57f 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -147,13 +147,14 @@ class phpbb_extension_manager_test extends phpbb_database_test_case protected function create_extension_manager($with_cache = true) { + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; $config = new \phpbb\config\config(array('version' => PHPBB_VERSION)); $db = $this->new_dbal(); $factory = new \phpbb\db\tools\factory(); + $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $php_ext); $db_tools = $factory->get($db); - $phpbb_root_path = __DIR__ . './../../phpBB/'; - $php_ext = 'php'; $table_prefix = 'phpbb_'; $container = new phpbb_mock_container_builder(); @@ -177,9 +178,9 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $container, $db, $config, + $finder_factory, 'phpbb_ext', __DIR__ . '/', - $php_ext, ($with_cache) ? new \phpbb\cache\service(new phpbb_mock_cache(), $config, $db, $phpbb_root_path, $php_ext) : null ); } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index e385ad323c..e4ae09064e 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -42,6 +42,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $factory = new \phpbb\db\tools\factory(); $this->db_tools = $factory->get($this->db); + $finder_factory = $this->createMock('\phpbb\finder\factory'); $this->phpbb_root_path = __DIR__ . '/'; $this->phpEx = 'php'; @@ -97,9 +98,9 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, + $finder_factory, 'phpbb_ext', $this->phpbb_root_path, - $this->phpEx, $this->cache ); diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index 5b73256fdd..db389929ed 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -23,6 +23,7 @@ class phpbb_mock_container_builder implements ContainerInterface $this->setParameter('debug.load_time', false); $this->setParameter('session.log_errors', false); $this->setParameter('session.force_sid', true); + $this->setParameter('finder.not_use_cache', false); } /** diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 0d6d110647..e38b1a1b1e 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -19,11 +19,11 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = 'php'; $this->extensions = $extensions; $this->filesystem = new \phpbb\filesystem\filesystem(); $this->container = $container; $this->config = new \phpbb\config\config(array()); $this->user = new \phpbb\user($lang,'\phpbb\datetime'); + $this->finder_factory = new \phpbb\finder\factory(null, true, $this->phpbb_root_path, $phpEx); } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index e9ffe62ad0..deaee99cd1 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -74,7 +74,7 @@ abstract class phpbb_database_test_case extends TestCase $setup_extensions = static::setup_extensions(); - $finder = new \phpbb\finder($phpbb_root_path, null, $phpEx); + $finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); $finder->core_path('phpbb/db/migration/data/'); if (!empty($setup_extensions)) { diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index ced91fa37e..fdc6736a80 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -365,7 +365,7 @@ class phpbb_database_test_connection_manager { global $phpbb_root_path, $phpEx, $table_prefix; - $finder = new \phpbb\finder($phpbb_root_path, null, $phpEx); + $finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); $classes = $finder->core_path('phpbb/db/migration/data/') ->get_classes(); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3300fc09c5..e94e233b22 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -239,6 +239,7 @@ class phpbb_functional_test_case extends phpbb_test_case $config = new \phpbb\config\config(array('version' => PHPBB_VERSION)); $db = $this->get_db(); $factory = new \phpbb\db\tools\factory(); + $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx); $db_tools = $factory->get($db); $container = new phpbb_mock_container_builder(); @@ -262,9 +263,9 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, + $finder_factory, self::$config['table_prefix'] . 'ext', __DIR__ . '/', - $phpEx, new \phpbb\cache\service($this->get_cache_driver(), $config, $this->db, $phpbb_root_path, $phpEx) ); From d31e9868154c64dea6a16f8cf88f93829b176337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Sep 2018 13:10:16 +0200 Subject: [PATCH 2/5] [ticket/12631] Rename finder.not_use_cache to finder.cache PHPBB3-12631 --- .../default/container/services_finder.yml | 2 +- phpBB/config/development/config.yml | 2 +- .../container/services_install_database.yml | 2 +- phpBB/develop/create_schema_files.php | 2 +- .../di/extension/container_configuration.php | 2 +- phpBB/phpbb/finder/factory.php | 21 ++++++++++--------- phpBB/phpbb/finder/finder.php | 8 +++---- .../task/create_schema_file.php | 8 +++---- tests/extension/finder_test.php | 4 ++-- tests/mock/container_builder.php | 1 + tests/mock/extension_manager.php | 2 +- .../phpbb_database_test_case.php | 2 +- ...phpbb_database_test_connection_manager.php | 2 +- 13 files changed, 30 insertions(+), 28 deletions(-) diff --git a/phpBB/config/default/container/services_finder.yml b/phpBB/config/default/container/services_finder.yml index 9937f35396..f42886df7f 100644 --- a/phpBB/config/default/container/services_finder.yml +++ b/phpBB/config/default/container/services_finder.yml @@ -3,6 +3,6 @@ services: class: phpbb\finder\factory arguments: - '@cache' - - '%finder.not_use_cache%' + - '%finder.cache%' - '%core.root_path%' - '%core.php_ext%' diff --git a/phpBB/config/development/config.yml b/phpBB/config/development/config.yml index fb96e5251c..37a690e036 100644 --- a/phpBB/config/development/config.yml +++ b/phpBB/config/development/config.yml @@ -27,4 +27,4 @@ core: log_errors: true finder: - not_use_cache: true + cache: false diff --git a/phpBB/config/installer/container/services_install_database.yml b/phpBB/config/installer/container/services_install_database.yml index 5f10ff0373..1ea5013ef1 100644 --- a/phpBB/config/installer/container/services_install_database.yml +++ b/phpBB/config/installer/container/services_install_database.yml @@ -8,7 +8,7 @@ services: - '%core.root_path%' - '%core.php_ext%' - '%tables%' - - '%finder.not_use_cache%' + - '%finder.cache%' tags: - { name: install_database_install, order: 1 } diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 912b681575..5288a84d6d 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -43,7 +43,7 @@ require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); -$finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); +$finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx); $classes = $finder->core_path('phpbb/') ->directory('/db/migration/data') ->get_classes(); diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index 4d23de22de..5e0c46b098 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -67,7 +67,7 @@ class container_configuration implements ConfigurationInterface ->arrayNode('finder') ->addDefaultsIfNotSet() ->children() - ->booleanNode('not_use_cache')->defaultValue(false)->end() + ->booleanNode('cache')->defaultValue(true)->end() ->end() ->end() ->end() diff --git a/phpBB/phpbb/finder/factory.php b/phpBB/phpbb/finder/factory.php index 21b568b735..3db960154f 100644 --- a/phpBB/phpbb/finder/factory.php +++ b/phpBB/phpbb/finder/factory.php @@ -19,23 +19,22 @@ namespace phpbb\finder; class factory { protected $cache; - protected $not_use_cache; + protected $use_cache; protected $phpbb_root_path; protected $php_ext; /** * Creates a new finder instance with its dependencies * - * @param string $phpbb_root_path Path to the phpbb root directory - * @param \phpbb\cache\service $cache A cache instance or null - * @param string $php_ext php file extension - * @param string $cache_name The name of the cache variable, defaults to - * _ext_finder + * @param \phpbb\cache\service $cache A cache instance or null + * @param bool $not_use_cache Use cache or not + * @param string $phpbb_root_path Path to the phpbb root directory + * @param string $php_ext php file extension */ - public function __construct(/*\phpbb\cache\service */ $cache, $not_use_cache, $phpbb_root_path, $php_ext) + public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext) { $this->cache = $cache; - $this->not_use_cache = $not_use_cache; + $this->use_cache = $use_cache; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } @@ -44,10 +43,12 @@ class factory * The cache variable name used to store $this->cached_queries in $this->cache. * * Allows the use of multiple differently configured finders with the same cache. - * @var string + * + * @param string $cache_name The name of the cache variable, defaults to + * _ext_finder */ public function get($cache_name = '_ext_finder') { - return new finder($this->cache, $this->not_use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name); + return new finder($this->cache, $this->use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name); } } diff --git a/phpBB/phpbb/finder/finder.php b/phpBB/phpbb/finder/finder.php index 80b98b5eff..5c88396299 100644 --- a/phpBB/phpbb/finder/finder.php +++ b/phpBB/phpbb/finder/finder.php @@ -23,7 +23,7 @@ class finder protected $extensions; protected $phpbb_root_path; protected $cache; - protected $not_use_cache; + protected $use_cache; protected $php_ext; /** @@ -56,11 +56,11 @@ class finder * @param string $cache_name The name of the cache variable, defaults to * _ext_finder */ - public function __construct(/*\phpbb\cache\service */ $cache, $not_use_cache, $phpbb_root_path, $php_ext, $cache_name = '_ext_finder') + public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext, $cache_name = '_ext_finder') { $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; - $this->not_use_cache = $not_use_cache; + $this->use_cache = $use_cache; $this->php_ext = $php_ext; $this->cache_name = $cache_name; @@ -426,7 +426,7 @@ class finder $this->query['is_dir'] = $is_dir; $query = md5(serialize($this->query) . serialize($extensions)); - if (!$this->not_use_cache && $cache && isset($this->cached_queries[$query])) + if ($this->use_cache && $cache && isset($this->cached_queries[$query])) { return $this->cached_queries[$query]; } diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php index 1788271365..695ec86143 100644 --- a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php +++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php @@ -48,7 +48,7 @@ class create_schema_file extends \phpbb\install\task_base /** * @var string */ - protected $not_use_cache; + protected $finder_cache; /** * Constructor @@ -64,7 +64,7 @@ class create_schema_file extends \phpbb\install\task_base \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, - $not_use_cache) + $finder_cache) { $dbms = $db_helper->get_available_dbms($config->get('dbms')); $dbms = $dbms[$config->get('dbms')]['DRIVER']; @@ -84,7 +84,7 @@ class create_schema_file extends \phpbb\install\task_base $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->not_use_cache = $not_use_cache; + $this->finder_cache = $finder_cache; parent::__construct(true); } @@ -124,7 +124,7 @@ class create_schema_file extends \phpbb\install\task_base include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); } - $finder = new \phpbb\finder\finder(null, true, $this->phpbb_root_path, $this->php_ext); + $finder = new \phpbb\finder\finder(null, $this->finder_cache, $this->phpbb_root_path, $this->php_ext); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $factory = new \phpbb\db\tools\factory(); $db_tools = $factory->get($this->db, true); diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 75d400269c..bd25b6caf9 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -243,7 +243,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new \phpbb\finder\finder($cache, true, __DIR__ . '/', 'php', '_custom_cache_name'); + $finder = new \phpbb\finder\finder($cache, false, __DIR__ . '/', 'php', '_custom_cache_name'); $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $files = $finder->suffix('_class.php')->get_files(); @@ -288,7 +288,7 @@ class phpbb_extension_finder_test extends phpbb_test_case md5(serialize($query)) => array('file_name' => 'extension'), ), )), - true, + false, __DIR__ . '/', '_ext_finder' ); diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index db389929ed..1a02ded887 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -24,6 +24,7 @@ class phpbb_mock_container_builder implements ContainerInterface $this->setParameter('session.log_errors', false); $this->setParameter('session.force_sid', true); $this->setParameter('finder.not_use_cache', false); + $this->setParameter('finder.cache', false); } /** diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index e38b1a1b1e..31412559c3 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -24,6 +24,6 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager $this->container = $container; $this->config = new \phpbb\config\config(array()); $this->user = new \phpbb\user($lang,'\phpbb\datetime'); - $this->finder_factory = new \phpbb\finder\factory(null, true, $this->phpbb_root_path, $phpEx); + $this->finder_factory = new \phpbb\finder\factory(null, false, $this->phpbb_root_path, $phpEx); } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index deaee99cd1..2b1b8269f7 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -74,7 +74,7 @@ abstract class phpbb_database_test_case extends TestCase $setup_extensions = static::setup_extensions(); - $finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); + $finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx); $finder->core_path('phpbb/db/migration/data/'); if (!empty($setup_extensions)) { diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index fdc6736a80..d2e16b9006 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -365,7 +365,7 @@ class phpbb_database_test_connection_manager { global $phpbb_root_path, $phpEx, $table_prefix; - $finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx); + $finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx); $classes = $finder->core_path('phpbb/db/migration/data/') ->get_classes(); From 0312aaa6dc6d3f95c3db22bf30d009024d5f2456 Mon Sep 17 00:00:00 2001 From: rubencm Date: Tue, 2 Apr 2019 17:51:12 +0000 Subject: [PATCH 3/5] [ticket/12631] Solve rebase issues PHPBB3-12631 --- phpBB/phpbb/di/extension/container_configuration.php | 2 ++ phpBB/phpbb/di/extension/core.php | 1 + phpBB/phpbb/finder/factory.php | 2 +- tests/mock/container_builder.php | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index 5e0c46b098..e74ae33e9b 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -64,6 +64,8 @@ class container_configuration implements ConfigurationInterface ->children() ->booleanNode('force_sid')->defaultValue(false)->end() ->booleanNode('log_errors')->defaultValue(false)->end() + ->end() + ->end() ->arrayNode('finder') ->addDefaultsIfNotSet() ->children() diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 20f3501be7..c0725942be 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -117,6 +117,7 @@ class core extends Extension foreach ($config['session'] as $name => $value) { $container->setParameter('session.' . $name, $value); + } // Set the finder options foreach ($config['finder'] as $name => $value) diff --git a/phpBB/phpbb/finder/factory.php b/phpBB/phpbb/finder/factory.php index 3db960154f..3022f5ea9d 100644 --- a/phpBB/phpbb/finder/factory.php +++ b/phpBB/phpbb/finder/factory.php @@ -27,7 +27,7 @@ class factory * Creates a new finder instance with its dependencies * * @param \phpbb\cache\service $cache A cache instance or null - * @param bool $not_use_cache Use cache or not + * @param bool $use_cache Use cache or not * @param string $phpbb_root_path Path to the phpbb root directory * @param string $php_ext php file extension */ diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index 1a02ded887..29050825db 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -23,7 +23,6 @@ class phpbb_mock_container_builder implements ContainerInterface $this->setParameter('debug.load_time', false); $this->setParameter('session.log_errors', false); $this->setParameter('session.force_sid', true); - $this->setParameter('finder.not_use_cache', false); $this->setParameter('finder.cache', false); } From ed1566d21730afc3dbcaa8e4e35c12f1e1fbfbae Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 10 Oct 2021 11:52:16 +0200 Subject: [PATCH 4/5] [ticket/12631] Remove invalid parameter for create_schema_file task PHPBB3-12631 --- phpBB/config/installer/container/services_install_database.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/config/installer/container/services_install_database.yml b/phpBB/config/installer/container/services_install_database.yml index 1ea5013ef1..3a11cdb8cb 100644 --- a/phpBB/config/installer/container/services_install_database.yml +++ b/phpBB/config/installer/container/services_install_database.yml @@ -7,7 +7,6 @@ services: - '@filesystem' - '%core.root_path%' - '%core.php_ext%' - - '%tables%' - '%finder.cache%' tags: - { name: install_database_install, order: 1 } From cdd1e7849a6eca963b0e3b47e221ca3ea4620be8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 10 Oct 2021 11:52:47 +0200 Subject: [PATCH 5/5] [ticket/12631] Some more cleanup and type hints for new finder files PHPBB3-12631 --- phpBB/phpbb/finder/factory.php | 12 +++++++----- phpBB/phpbb/finder/finder.php | 8 +++++--- .../install_database/task/create_schema_file.php | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/finder/factory.php b/phpBB/phpbb/finder/factory.php index 3022f5ea9d..0ce087b061 100644 --- a/phpBB/phpbb/finder/factory.php +++ b/phpBB/phpbb/finder/factory.php @@ -13,6 +13,8 @@ namespace phpbb\finder; +use phpbb\cache\service; + /** * The finder provides a simple way to locate files in the core and a set of extensions */ @@ -26,12 +28,12 @@ class factory /** * Creates a new finder instance with its dependencies * - * @param \phpbb\cache\service $cache A cache instance or null + * @param service|null $cache A cache instance or null * @param bool $use_cache Use cache or not * @param string $phpbb_root_path Path to the phpbb root directory * @param string $php_ext php file extension */ - public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext) + public function __construct(?service $cache, bool $use_cache, string $phpbb_root_path, string $php_ext) { $this->cache = $cache; $this->use_cache = $use_cache; @@ -44,10 +46,10 @@ class factory * * Allows the use of multiple differently configured finders with the same cache. * - * @param string $cache_name The name of the cache variable, defaults to - * _ext_finder + * @param string $cache_name The name of the cache variable, defaults to _ext_finder + * @return finder New instance of finder */ - public function get($cache_name = '_ext_finder') + public function get(string $cache_name = '_ext_finder'): finder { return new finder($this->cache, $this->use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name); } diff --git a/phpBB/phpbb/finder/finder.php b/phpBB/phpbb/finder/finder.php index 5c88396299..6b0baef19f 100644 --- a/phpBB/phpbb/finder/finder.php +++ b/phpBB/phpbb/finder/finder.php @@ -13,6 +13,7 @@ namespace phpbb\finder; +use phpbb\cache\service; use phpbb\filesystem\helper as filesystem_helper; /** @@ -51,12 +52,13 @@ class finder * Creates a new finder instance with its dependencies * * @param string $phpbb_root_path Path to the phpbb root directory - * @param \phpbb\cache\service|null $cache A cache instance or null + * @param service|null $cache A cache instance or null + * @param bool $use_cache Flag whether cache should be used * @param string $php_ext php file extension * @param string $cache_name The name of the cache variable, defaults to - * _ext_finder + * _ext_finder */ - public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext, $cache_name = '_ext_finder') + public function __construct(?service $cache, bool $use_cache, string $phpbb_root_path, string $php_ext, string $cache_name = '_ext_finder') { $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php index 695ec86143..984ca3461e 100644 --- a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php +++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php @@ -46,7 +46,7 @@ class create_schema_file extends \phpbb\install\task_base protected $php_ext; /** - * @var string + * @var bool */ protected $finder_cache; @@ -58,6 +58,7 @@ class create_schema_file extends \phpbb\install\task_base * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service * @param string $phpbb_root_path Path phpBB's root * @param string $php_ext Extension of PHP files + * @param bool $finder_cache Flag whether to cache finder */ public function __construct(\phpbb\install\helper\config $config, \phpbb\install\helper\database $db_helper, @@ -124,7 +125,8 @@ class create_schema_file extends \phpbb\install\task_base include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); } - $finder = new \phpbb\finder\finder(null, $this->finder_cache, $this->phpbb_root_path, $this->php_ext); + $finder_factory = new \phpbb\finder\factory(null, $this->finder_cache, $this->phpbb_root_path, $this->php_ext); + $finder = $finder_factory->get(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $factory = new \phpbb\db\tools\factory(); $db_tools = $factory->get($this->db, true);