mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-19 05:49:44 +02:00
[ticket/12508] Remove extension manager from finder
PHPBB3-12508
This commit is contained in:
parent
0aa6381834
commit
c20653dfbe
@ -18,7 +18,7 @@ namespace phpbb\extension;
|
|||||||
*/
|
*/
|
||||||
class finder
|
class finder
|
||||||
{
|
{
|
||||||
protected $extension_manager;
|
protected $extensions;
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
@ -48,9 +48,6 @@ class finder
|
|||||||
/**
|
/**
|
||||||
* Creates a new finder instance with its dependencies
|
* 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 \phpbb\filesystem $filesystem Filesystem instance
|
||||||
* @param string $phpbb_root_path Path to the phpbb root directory
|
* @param string $phpbb_root_path Path to the phpbb root directory
|
||||||
* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null
|
* @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
|
* @param string $cache_name The name of the cache variable, defaults to
|
||||||
* _ext_finder
|
* _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->filesystem = $filesystem;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
@ -76,10 +72,23 @@ class finder
|
|||||||
'extension_prefix' => false,
|
'extension_prefix' => false,
|
||||||
'extension_directory' => false,
|
'extension_directory' => false,
|
||||||
);
|
);
|
||||||
|
$this->extensions = array();
|
||||||
|
|
||||||
$this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false;
|
$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
|
* 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.
|
* 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, $use_all_available = false)
|
public function get_classes($cache = true)
|
||||||
{
|
{
|
||||||
$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, $use_all_available);
|
$files = $this->find($cache, false);
|
||||||
|
|
||||||
return $this->get_classes_from_files($files);
|
return $this->get_classes_from_files($files);
|
||||||
}
|
}
|
||||||
@ -290,27 +297,23 @@ class 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, $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.
|
* 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, $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 $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
|
|
||||||
* 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, $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();
|
$result = array();
|
||||||
foreach ($items as $item => $ext_name)
|
foreach ($items as $item => $ext_name)
|
||||||
@ -351,21 +350,11 @@ class 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, $use_all_available = false)
|
public function find($cache = true, $is_dir = false)
|
||||||
{
|
{
|
||||||
if ($use_all_available)
|
$extensions = $this->extensions;
|
||||||
{
|
|
||||||
$extensions = $this->extension_manager->all_available();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$extensions = $this->extension_manager->all_enabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->query['core_path'])
|
if ($this->query['core_path'])
|
||||||
{
|
{
|
||||||
$extensions['/'] = $this->phpbb_root_path . $this->query['core_path'];
|
$extensions['/'] = $this->phpbb_root_path . $this->query['core_path'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user