From c20653dfbe552b53fa3281ff8f2a9214fc8a26a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 May 2014 17:22:11 +0200 Subject: [PATCH 1/9] [ticket/12508] Remove extension manager from finder PHPBB3-12508 --- phpBB/phpbb/extension/finder.php | 61 +++++++++++++------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/phpBB/phpbb/extension/finder.php b/phpBB/phpbb/extension/finder.php index 6f2408094e..b67c0709a4 100644 --- a/phpBB/phpbb/extension/finder.php +++ b/phpBB/phpbb/extension/finder.php @@ -18,7 +18,7 @@ namespace phpbb\extension; */ class finder { - protected $extension_manager; + protected $extensions; protected $filesystem; protected $phpbb_root_path; protected $cache; @@ -48,9 +48,6 @@ class finder /** * Creates a new finder instance with its dependencies * - * @param \phpbb\extension\manager $extension_manager An extension manager - * instance that provides the finder with a list of active - * extensions and their locations * @param \phpbb\filesystem $filesystem Filesystem instance * @param string $phpbb_root_path Path to the phpbb root directory * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null @@ -58,9 +55,8 @@ class finder * @param string $cache_name The name of the cache variable, defaults to * _ext_finder */ - public function __construct(\phpbb\extension\manager $extension_manager, \phpbb\filesystem $filesystem, $phpbb_root_path = '', \phpbb\cache\driver\driver_interface $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') + public function __construct(\phpbb\filesystem $filesystem, $phpbb_root_path = '', \phpbb\cache\driver\driver_interface $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') { - $this->extension_manager = $extension_manager; $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; @@ -76,10 +72,23 @@ class finder 'extension_prefix' => false, 'extension_directory' => false, ); + $this->extensions = array(); $this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false; } + /** + * Set the array of extensions + * + * @param array $extensions A list of extensions that should be searched aswell + * @return \phpbb\extension\finder This object for chaining calls + */ + public function set_extensions(array $extensions) + { + $this->extensions = $extensions; + return $this; + } + /** * Sets a core path to be searched in addition to extensions * @@ -246,16 +255,14 @@ class finder * phpBB naming rules an incorrect class name will be returned. * * @param bool $cache Whether the result should be cached - * @param bool $use_all_available Use all available instead of just all - * enabled extensions * @return array An array of found class names */ - public function get_classes($cache = true, $use_all_available = false) + public function get_classes($cache = true) { $this->query['extension_suffix'] .= '.' . $this->php_ext; $this->query['core_suffix'] .= '.' . $this->php_ext; - $files = $this->find($cache, false, $use_all_available); + $files = $this->find($cache, false); return $this->get_classes_from_files($files); } @@ -290,27 +297,23 @@ class finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached - * @param bool $use_all_available Use all available instead of just all - * enabled extensions * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true, $use_all_available = false, $extension_keys = false) + public function get_directories($cache = true, $extension_keys = false) { - return $this->find_with_root_path($cache, true, $use_all_available, $extension_keys); + return $this->find_with_root_path($cache, true, $extension_keys); } /** * Finds all files matching the configured options. * * @param bool $cache Whether the result should be cached - * @param bool $use_all_available Use all available instead of just all - * enabled extensions * @return array An array of paths to found files */ - public function get_files($cache = true, $use_all_available = false) + public function get_files($cache = true) { - return $this->find_with_root_path($cache, false, $use_all_available); + return $this->find_with_root_path($cache, false); } /** @@ -319,15 +322,11 @@ class finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise - * @param bool $use_all_available Use all available instead of just all - * enabled extensions - * @param bool $extension_keys If true, result will be associative array - * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false, $use_all_available = false, $extension_keys = false) + protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) { - $items = $this->find($cache, $is_dir, $use_all_available); + $items = $this->find($cache, $is_dir); $result = array(); foreach ($items as $item => $ext_name) @@ -351,21 +350,11 @@ class finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise - * @param bool $use_all_available Use all available instead of just all - * enabled extensions * @return array An array of paths to found items */ - public function find($cache = true, $is_dir = false, $use_all_available = false) + public function find($cache = true, $is_dir = false) { - if ($use_all_available) - { - $extensions = $this->extension_manager->all_available(); - } - else - { - $extensions = $this->extension_manager->all_enabled(); - } - + $extensions = $this->extensions; if ($this->query['core_path']) { $extensions['/'] = $this->phpbb_root_path . $this->query['core_path']; From d45c681b40cf0415ce49b2cd7f3f1083e84b367c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 May 2014 17:50:46 +0200 Subject: [PATCH 2/9] [ticket/12508] Fix usages of the finder PHPBB3-12508 --- phpBB/develop/create_schema_files.php | 12 ++---------- phpBB/includes/acp/acp_modules.php | 4 ++-- phpBB/phpbb/extension/manager.php | 14 ++++++++++++-- tests/controller/helper_route_test.php | 2 +- tests/extension/finder_test.php | 5 +++-- tests/pagination/pagination_test.php | 6 +++--- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 5490e45afa..b12f5e4d25 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -44,17 +44,9 @@ 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(); -class phpbb_extension_empty_manager extends \phpbb\extension\manager -{ - public function __construct() - { - $this->extensions = array(); - } -} - -$finder = new \phpbb\extension\finder(new \phpbb_extension_empty_manager(), new \phpbb\filesystem(), $phpbb_root_path); +$finder = new \phpbb\extension\finder(new \phpbb\filesystem(), $phpbb_root_path); $classes = $finder->core_path('phpbb/') - ->directory('db/migration/data') + ->directory('/db/migration/data') ->get_classes(); $db = new \phpbb\db\driver\sqlite(); diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 61bae18557..5932f4cddd 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -561,14 +561,14 @@ class acp_modules $directory = $phpbb_root_path . 'includes/' . $module_class . '/info/'; $fileinfo = array(); - $finder = $phpbb_extension_manager->get_finder(); + $finder = $phpbb_extension_manager->get_finder($use_all_available); $modules = $finder ->extension_suffix('_module') ->extension_directory("/$module_class") ->core_path("includes/$module_class/info/") ->core_prefix($module_class . '_') - ->get_classes(true, $use_all_available); + ->get_classes(true); foreach ($modules as $cur_module) { diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index cd7289e085..88404b025e 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -534,10 +534,20 @@ class manager /** * Instantiates a \phpbb\extension\finder. * + * @param bool $use_all_available Should we load all extensions, or just enabled ones * @return \phpbb\extension\finder An extension finder instance */ - public function get_finder() + public function get_finder($use_all_available = false) { - return new \phpbb\extension\finder($this, $this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); + $finder = new \phpbb\extension\finder($this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); + if ($use_all_available) + { + $finder->set_extensions($this->all_available()); + } + else + { + $finder->set_extensions($this->all_enabled()); + } + return $finder; } } diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php index df0794a047..3756082be6 100644 --- a/tests/controller/helper_route_test.php +++ b/tests/controller/helper_route_test.php @@ -43,11 +43,11 @@ class phpbb_controller_helper_route_test extends phpbb_test_case ); $finder = new \phpbb\extension\finder( - $this->extension_manager, new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache() ); + $finder->set_extensions($this->extension_manager->all_enabled()); $this->provider = new \phpbb\controller\provider(); $this->provider->find_routing_files($finder); $this->provider->find(dirname(__FILE__) . '/'); diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 8cc5146b33..0cf268d32b 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -201,7 +201,8 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new \phpbb\extension\finder($this->extension_manager, new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $finder = new \phpbb\extension\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $finder->set_extensions($this->extension_manager->all_enabled()); $files = $finder->suffix('_class.php')->get_files(); $expected_files = array( @@ -240,7 +241,6 @@ class phpbb_extension_finder_test extends phpbb_test_case ); $finder = new \phpbb\extension\finder( - $this->extension_manager, new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache(array( @@ -249,6 +249,7 @@ class phpbb_extension_finder_test extends phpbb_test_case ), )) ); + $finder->set_extensions($this->extension_manager->all_enabled()); $classes = $finder ->core_path($query['core_path']) diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index e233264cc6..4d6fbac20e 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -35,16 +35,16 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case ->will($this->returnCallback(array($this, 'return_callback_implode'))); $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); - $this->finder = new \phpbb\extension\finder( - $manager, + $finder = new \phpbb\extension\finder( new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache() ); + $finder->set_extensions($manager->all_enabled()); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $provider = new \phpbb\controller\provider(); - $provider->find_routing_files($this->finder); + $provider->find_routing_files($finder); $provider->find(dirname(__FILE__) . '/'); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, '', 'php', dirname(__FILE__) . '/'); $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper); From 183492b01931dec5052e2087f70fa432a2f51b03 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 May 2014 18:27:30 +0200 Subject: [PATCH 3/9] [ticket/12508] Move \phpbb\extension\finder to \phpbb\finder PHPBB3-12508 --- phpBB/develop/create_schema_files.php | 2 +- phpBB/phpbb/controller/provider.php | 4 ++-- phpBB/phpbb/db/migrator.php | 4 ++-- phpBB/phpbb/extension/base.php | 6 +++--- phpBB/phpbb/extension/manager.php | 6 +++--- phpBB/phpbb/{extension => }/finder.php | 24 ++++++++++++------------ tests/controller/helper_route_test.php | 2 +- tests/extension/finder_test.php | 4 ++-- tests/pagination/pagination_test.php | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) rename phpBB/phpbb/{extension => }/finder.php (94%) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index b12f5e4d25..05085d39ab 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -44,7 +44,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\extension\finder(new \phpbb\filesystem(), $phpbb_root_path); +$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path); $classes = $finder->core_path('phpbb/') ->directory('/db/migration/data') ->get_classes(); diff --git a/phpBB/phpbb/controller/provider.php b/phpBB/phpbb/controller/provider.php index 91f3a07fb1..bd85385a41 100644 --- a/phpBB/phpbb/controller/provider.php +++ b/phpBB/phpbb/controller/provider.php @@ -46,10 +46,10 @@ class provider } /** - * @param \phpbb\extension\finder $finder + * @param \phpbb\finder $finder * @return null */ - public function find_routing_files(\phpbb\extension\finder $finder) + public function find_routing_files(\phpbb\finder $finder) { // We hardcode the path to the core config directory // because the finder cannot find it diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 9b9532a7ad..5255c73c1c 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -714,7 +714,7 @@ class migrator /** * Load migration data files from a directory * - * @param \phpbb\extension\finder $finder + * @param \phpbb\finder $finder * @param string $path Path to migration data files * @param bool $check_fulfillable If TRUE (default), we will check * if all of the migrations are fulfillable after loading them. @@ -723,7 +723,7 @@ class migrator * with the last call to prevent throwing errors unnecessarily). * @return array Array of migration names */ - public function load_migrations(\phpbb\extension\finder $finder, $path, $check_fulfillable = true) + public function load_migrations(\phpbb\finder $finder, $path, $check_fulfillable = true) { if (!is_dir($path)) { diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index eb306aeb72..cbbd7bc622 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\extension\finder */ + /** @var \phpbb\finder */ protected $finder; /** @var \phpbb\db\migrator */ @@ -39,11 +39,11 @@ class base implements \phpbb\extension\extension_interface * Constructor * * @param ContainerInterface $container Container object - * @param \phpbb\extension\finder $extension_finder + * @param \phpbb\finder $extension_finder * @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\extension\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path) + public function __construct(ContainerInterface $container, \phpbb\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 88404b025e..bfc6e19b5b 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -532,14 +532,14 @@ class manager } /** - * Instantiates a \phpbb\extension\finder. + * Instantiates a \phpbb\finder. * * @param bool $use_all_available Should we load all extensions, or just enabled ones - * @return \phpbb\extension\finder An extension finder instance + * @return \phpbb\finder An extension finder instance */ public function get_finder($use_all_available = false) { - $finder = new \phpbb\extension\finder($this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); + $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); if ($use_all_available) { $finder->set_extensions($this->all_available()); diff --git a/phpBB/phpbb/extension/finder.php b/phpBB/phpbb/finder.php similarity index 94% rename from phpBB/phpbb/extension/finder.php rename to phpBB/phpbb/finder.php index b67c0709a4..d3eed44c12 100644 --- a/phpBB/phpbb/extension/finder.php +++ b/phpBB/phpbb/finder.php @@ -11,7 +11,7 @@ * */ -namespace phpbb\extension; +namespace phpbb; /** * The extension finder provides a simple way to locate files in active extensions @@ -81,7 +81,7 @@ class finder * Set the array of extensions * * @param array $extensions A list of extensions that should be searched aswell - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function set_extensions(array $extensions) { @@ -93,7 +93,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\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function core_path($core_path) { @@ -109,7 +109,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $suffix A filename suffix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function suffix($suffix) { @@ -126,7 +126,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $extension_suffix A filename suffix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function extension_suffix($extension_suffix) { @@ -142,7 +142,7 @@ class finder * file extension is automatically added to suffixes. * * @param string $core_suffix A filename suffix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function core_suffix($core_suffix) { @@ -154,7 +154,7 @@ class finder * Sets the prefix all files found in extensions and core must match * * @param string $prefix A filename prefix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function prefix($prefix) { @@ -167,7 +167,7 @@ class finder * Sets a prefix all files found in extensions must match * * @param string $extension_prefix A filename prefix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function extension_prefix($extension_prefix) { @@ -179,7 +179,7 @@ class finder * Sets a prefix all files found in the core path must match * * @param string $core_prefix A filename prefix - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function core_prefix($core_prefix) { @@ -194,7 +194,7 @@ class finder * the current directory. * * @param string $directory - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function directory($directory) { @@ -207,7 +207,7 @@ class finder * Sets a directory all files found in extensions must be contained in * * @param string $extension_directory - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function extension_directory($extension_directory) { @@ -219,7 +219,7 @@ class finder * Sets a directory all files found in the core path must be contained in * * @param string $core_directory - * @return \phpbb\extension\finder This object for chaining calls + * @return \phpbb\finder This object for chaining calls */ public function core_directory($core_directory) { diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php index 3756082be6..f604f5d892 100644 --- a/tests/controller/helper_route_test.php +++ b/tests/controller/helper_route_test.php @@ -42,7 +42,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case ) ); - $finder = new \phpbb\extension\finder( + $finder = new \phpbb\finder( new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache() diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 0cf268d32b..fa30127ca0 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -201,7 +201,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\extension\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); $finder->set_extensions($this->extension_manager->all_enabled()); $files = $finder->suffix('_class.php')->get_files(); @@ -240,7 +240,7 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $finder = new \phpbb\extension\finder( + $finder = new \phpbb\finder( new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache(array( diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 4d6fbac20e..ecdacc21a4 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -35,7 +35,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case ->will($this->returnCallback(array($this, 'return_callback_implode'))); $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); - $finder = new \phpbb\extension\finder( + $finder = new \phpbb\finder( new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache() From e1707b27ca8b998652fddee571197b24974ebb2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 May 2014 00:14:44 +0200 Subject: [PATCH 4/9] [ticket/12508] Fix class doc block PHPBB3-12508 --- phpBB/phpbb/finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder.php index d3eed44c12..899dc4f290 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder.php @@ -14,7 +14,7 @@ namespace phpbb; /** -* The extension finder provides a simple way to locate files in active extensions +* The finder provides a simple way to locate files in the core and a set of extensions */ class finder { From 6980fbd27bd57dc01d7265cc742ab01a4bd9f93a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 May 2014 09:24:30 +0200 Subject: [PATCH 5/9] [ticket/12508] Only take a list of names for set_extensions() PHPBB3-12508 --- phpBB/phpbb/extension/manager.php | 4 ++-- phpBB/phpbb/finder.php | 14 +++++++++++--- tests/controller/helper_route_test.php | 2 +- tests/extension/finder_test.php | 4 ++-- tests/pagination/pagination_test.php | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index bfc6e19b5b..b83bb1b189 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -542,11 +542,11 @@ class manager $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); if ($use_all_available) { - $finder->set_extensions($this->all_available()); + $finder->set_extensions(array_keys($this->all_available())); } else { - $finder->set_extensions($this->all_enabled()); + $finder->set_extensions(array_keys($this->all_enabled())); } return $finder; } diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder.php index 899dc4f290..77a8222b84 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder.php @@ -80,12 +80,20 @@ class finder /** * Set the array of extensions * - * @param array $extensions A list of extensions that should be searched aswell + * @param array $extensions A list of extensions that should be searched aswell + * @param bool $replace_list Should the list be emptied before adding the extensions * @return \phpbb\finder This object for chaining calls */ - public function set_extensions(array $extensions) + public function set_extensions(array $extensions, $replace_list = true) { - $this->extensions = $extensions; + if ($replace_list) + { + $this->extensions = array(); + } + foreach ($extensions as $ext_name) + { + $this->extensions[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/'; + } return $this; } diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php index f604f5d892..621efaa830 100644 --- a/tests/controller/helper_route_test.php +++ b/tests/controller/helper_route_test.php @@ -47,7 +47,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case dirname(__FILE__) . '/', new phpbb_mock_cache() ); - $finder->set_extensions($this->extension_manager->all_enabled()); + $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $this->provider = new \phpbb\controller\provider(); $this->provider->find_routing_files($finder); $this->provider->find(dirname(__FILE__) . '/'); diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index fa30127ca0..5ff4c59722 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -202,7 +202,7 @@ class phpbb_extension_finder_test extends phpbb_test_case { $cache = new phpbb_mock_cache; $finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); - $finder->set_extensions($this->extension_manager->all_enabled()); + $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $files = $finder->suffix('_class.php')->get_files(); $expected_files = array( @@ -249,7 +249,7 @@ class phpbb_extension_finder_test extends phpbb_test_case ), )) ); - $finder->set_extensions($this->extension_manager->all_enabled()); + $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $classes = $finder ->core_path($query['core_path']) diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index ecdacc21a4..f253118253 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -40,7 +40,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case dirname(__FILE__) . '/', new phpbb_mock_cache() ); - $finder->set_extensions($manager->all_enabled()); + $finder->set_extensions(array_keys($manager->all_enabled())); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $provider = new \phpbb\controller\provider(); From fb3c6b94aeaf77b40e815c65e0982f38aebd7384 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 May 2014 09:41:49 +0200 Subject: [PATCH 6/9] [ticket/12508] Add a unit test for set_extensions() PHPBB3-12508 --- tests/extension/finder_test.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 5ff4c59722..2116cc057b 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -14,7 +14,9 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_extension_finder_test extends phpbb_test_case { + /** @var \phpbb\extension\manager */ protected $extension_manager; + /** @var \phpbb\finder */ protected $finder; public function setUp() @@ -56,6 +58,47 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function set_extensions_data() + { + return array( + array( + array(), + array('\phpbb\default\implementation'), + ), + array( + array('vendor3/bar'), + array( + '\phpbb\default\implementation', + '\vendor3\bar\my\hidden_class', + ), + ), + array( + array('vendor2/foo', 'vendor3/bar'), + array( + '\phpbb\default\implementation', + '\vendor2\foo\a_class', + '\vendor2\foo\b_class', + '\vendor3\bar\my\hidden_class', + ), + ), + ); + } + + /** + * @dataProvider set_extensions_data + */ + public function test_set_extensions($extensions, $expected) + { + $classes = $this->finder + ->set_extensions($extensions) + ->core_path('phpbb/default/') + ->extension_suffix('_class') + ->get_classes(); + + sort($classes); + $this->assertEquals($expected, $classes); + } + public function test_get_directories() { $dirs = $this->finder From 1e9492bcaafc53bd2ed72c04ee2b1a2be794c987 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 May 2014 15:14:50 +0200 Subject: [PATCH 7/9] [ticket/12508] Add new line to separate the if and foreach better PHPBB3-12508 --- phpBB/phpbb/finder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder.php index 77a8222b84..f1c0c424a6 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder.php @@ -90,6 +90,7 @@ class finder { $this->extensions = array(); } + foreach ($extensions as $ext_name) { $this->extensions[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/'; From c82ae94f8ac4b40368670ddb0d9540a036e7a5d7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 Jun 2014 00:11:53 +0200 Subject: [PATCH 8/9] [ticket/12508] Fix doc block PHPBB3-12508 --- phpBB/phpbb/finder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/finder.php b/phpBB/phpbb/finder.php index f1c0c424a6..28f28825ba 100644 --- a/phpBB/phpbb/finder.php +++ b/phpBB/phpbb/finder.php @@ -330,7 +330,9 @@ class finder * * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files - * otherwise + * otherwise + * @param bool $extension_keys If true, result will be associative array + * with extension name as key * @return array An array of paths to found items */ protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) From 0134acd53fb93ef64b60504ac73e20dc27910578 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 11:50:11 +0200 Subject: [PATCH 9/9] [ticket/12508] Ignore extensions in migration_tips dev tool PHPBB3-12508 --- phpBB/phpbb/console/command/dev/migration_tips.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/console/command/dev/migration_tips.php b/phpBB/phpbb/console/command/dev/migration_tips.php index 62a0a68865..c2f61568ea 100644 --- a/phpBB/phpbb/console/command/dev/migration_tips.php +++ b/phpBB/phpbb/console/command/dev/migration_tips.php @@ -37,6 +37,7 @@ class migration_tips extends \phpbb\console\command\command protected function execute(InputInterface $input, OutputInterface $output) { $migrations = $this->extension_manager->get_finder() + ->set_extensions(array()) ->core_path('phpbb/db/migration/data/') ->get_classes(); $tips = $migrations;