Merge remote-tracking branch 'EXreaction/ticket/11381' into develop

# By Nathaniel Guse
# Via Nathaniel Guse
* EXreaction/ticket/11381:
  [ticket/11381] Make finder able to search in all available extensions
This commit is contained in:
David King 2013-03-01 15:01:18 -05:00
commit eb7c8592d9
2 changed files with 28 additions and 11 deletions

View file

@ -247,14 +247,16 @@ class phpbb_extension_finder
* phpBB naming rules an incorrect class name will be returned. * phpBB naming rules an incorrect class name will be returned.
* *
* @param bool $cache Whether the result should be cached * @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 * @return array An array of found class names
*/ */
public function get_classes($cache = true) public function get_classes($cache = true, $use_all_available = false)
{ {
$this->query['extension_suffix'] .= $this->php_ext; $this->query['extension_suffix'] .= $this->php_ext;
$this->query['core_suffix'] .= $this->php_ext; $this->query['core_suffix'] .= $this->php_ext;
$files = $this->find($cache, false); $files = $this->find($cache, false, $use_all_available);
$classes = array(); $classes = array();
foreach ($files as $file => $ext_name) foreach ($files as $file => $ext_name)
@ -270,23 +272,27 @@ class phpbb_extension_finder
* Finds all directories matching the configured options * Finds all directories matching the configured options
* *
* @param bool $cache Whether the result should be cached * @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 * @param bool $extension_keys Whether the result should have extension name as array key
* @return array An array of paths to found directories * @return array An array of paths to found directories
*/ */
public function get_directories($cache = true, $extension_keys = false) public function get_directories($cache = true, $use_all_available = false, $extension_keys = false)
{ {
return $this->find_with_root_path($cache, true, $extension_keys); return $this->find_with_root_path($cache, true, $use_all_available, $extension_keys);
} }
/** /**
* Finds all files matching the configured options. * Finds all files matching the configured options.
* *
* @param bool $cache Whether the result should be cached * @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 * @return array An array of paths to found files
*/ */
public function get_files($cache = true) public function get_files($cache = true, $use_all_available = false)
{ {
return $this->find_with_root_path($cache, false); return $this->find_with_root_path($cache, false, $use_all_available);
} }
/** /**
@ -295,13 +301,15 @@ class phpbb_extension_finder
* @param bool $cache Whether the result should be cached * @param bool $cache Whether the result should be cached
* @param bool $is_dir Directories will be returned when true, only files * @param bool $is_dir Directories will be returned when true, only files
* otherwise * 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 * @param bool $extension_keys If true, result will be associative array
* with extension name as key * with extension name as key
* @return array An array of paths to found items * @return array An array of paths to found items
*/ */
protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) protected function find_with_root_path($cache = true, $is_dir = false, $use_all_available = false, $extension_keys = false)
{ {
$items = $this->find($cache, $is_dir); $items = $this->find($cache, $is_dir, $use_all_available);
$result = array(); $result = array();
foreach ($items as $item => $ext_name) foreach ($items as $item => $ext_name)
@ -325,9 +333,11 @@ class phpbb_extension_finder
* @param bool $cache Whether the result should be cached * @param bool $cache Whether the result should be cached
* @param bool $is_dir Directories will be returned when true, only files * @param bool $is_dir Directories will be returned when true, only files
* otherwise * otherwise
* @param bool $use_all_available Use all available instead of just all
* enabled extensions
* @return array An array of paths to found items * @return array An array of paths to found items
*/ */
public function find($cache = true, $is_dir = false) public function find($cache = true, $is_dir = false, $use_all_available = false)
{ {
$this->query['is_dir'] = $is_dir; $this->query['is_dir'] = $is_dir;
$query = md5(serialize($this->query)); $query = md5(serialize($this->query));
@ -339,7 +349,14 @@ class phpbb_extension_finder
$files = array(); $files = array();
if ($use_all_available)
{
$extensions = $this->extension_manager->all_available();
}
else
{
$extensions = $this->extension_manager->all_enabled(); $extensions = $this->extension_manager->all_enabled();
}
if ($this->query['core_path']) if ($this->query['core_path'])
{ {

View file

@ -92,7 +92,7 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple
if ($path && !phpbb_is_absolute($path)) if ($path && !phpbb_is_absolute($path))
{ {
$result = $finder->directory('/' . $this->ext_dir_prefix . $path) $result = $finder->directory('/' . $this->ext_dir_prefix . $path)
->get_directories(true, true); ->get_directories(true, false, true);
foreach ($result as $ext => $ext_path) foreach ($result as $ext => $ext_path)
{ {
$directories[$ext][] = $ext_path; $directories[$ext][] = $ext_path;