diff options
| author | David King <imkingdavid@gmail.com> | 2013-03-02 17:12:43 -0500 | 
|---|---|---|
| committer | David King <imkingdavid@gmail.com> | 2013-03-02 17:12:43 -0500 | 
| commit | e08edd36b9f18b9206ea327bcfb45e4331630d1b (patch) | |
| tree | 4f3b5d9aca26191bb65695f1b800cf21be51075f /phpBB/includes/extension | |
| parent | 9fca8f88fa533c9f8cae80ec5d92f2961006e982 (diff) | |
| parent | 91be99822312d9a83ae4f6849eef864dfd47e4a1 (diff) | |
| download | forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.gz forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.bz2 forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.xz forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.zip  | |
Merge remote-tracking branch 'EXreaction/ticket/11386' into develop
# By Nathaniel Guse
# Via Nathaniel Guse
* EXreaction/ticket/11386:
  [ticket/11386] Fix failing tests from constructor changes
  [ticket/11386] Fix circular reference error & serialize error
  [ticket/11386] Remove tests that check if finder cache is working
  [ticket/11386] Forgot to get the migration classes
  [ticket/11386] Update tests with new constructors for ext.manager/migrator
  [ticket/11386] Use finder to find migration files
Diffstat (limited to 'phpBB/includes/extension')
| -rw-r--r-- | phpBB/includes/extension/finder.php | 61 | ||||
| -rw-r--r-- | phpBB/includes/extension/manager.php | 11 | 
2 files changed, 59 insertions, 13 deletions
diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index af31478337..f71e32bc8d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -258,6 +258,17 @@ class phpbb_extension_finder  		$files = $this->find($cache, false, $use_all_available); +		return $this->get_classes_from_files($files); +	} + +	/** +	* Get class names from a list of files +	* +	* @param array $files Array of files (from find()) +	* @return array Array of class names +	*/ +	public function get_classes_from_files($files) +	{  		$classes = array();  		foreach ($files as $file => $ext_name)  		{ @@ -339,16 +350,6 @@ class phpbb_extension_finder  	*/  	public function find($cache = true, $is_dir = false, $use_all_available = false)  	{ -		$this->query['is_dir'] = $is_dir; -		$query = md5(serialize($this->query)); - -		if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) -		{ -			return $this->cached_queries[$query]; -		} - -		$files = array(); -  		if ($use_all_available)  		{  			$extensions = $this->extension_manager->all_available(); @@ -363,6 +364,39 @@ class phpbb_extension_finder  			$extensions['/'] = $this->phpbb_root_path . $this->query['core_path'];  		} +		$files = array(); +		$file_list = $this->find_from_paths($extensions, $cache, $is_dir); + +		foreach ($file_list as $file) +		{ +			$files[$file['named_path']] = $file['ext_name']; +		} + +		return $files; +	} + +	/** +	* Finds all file system entries matching the configured options from +	* an array of paths +	* +	* @param array $extensions Array of extensions (name => full relative path) +	* @param bool $cache Whether the result should be cached +	* @param bool $is_dir Directories will be returned when true, only files +	*                     otherwise +	* @return array An array of paths to found items +	*/ +	public function find_from_paths($extensions, $cache = true, $is_dir = false) +	{ +		$this->query['is_dir'] = $is_dir; +		$query = md5(serialize($this->query) . serialize($extensions)); + +		if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) +		{ +			return $this->cached_queries[$query]; +		} + +		$files = array(); +  		foreach ($extensions as $name => $path)  		{  			$ext_name = $name; @@ -436,7 +470,12 @@ class phpbb_extension_finder  						(!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) &&  						(!$directory || preg_match($directory_pattern, $relative_path)))  					{ -						$files[str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1))] = $ext_name; +						$files[] = array( +							'named_path'	=> str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)), +							'ext_name'		=> $ext_name, +							'path'			=> str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/', +							'filename'		=> $filename, +						);  					}  				}  			} diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 21a9ec1370..0d760681b9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -49,13 +49,12 @@ class phpbb_extension_manager  	* @param phpbb_cache_driver_interface $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 $db, phpbb_config $config, phpbb_db_migrator $migrator, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') +	public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')  	{  		$this->container = $container;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->db = $db;  		$this->config = $config; -		$this->migrator = $migrator;  		$this->cache = $cache;  		$this->php_ext = $php_ext;  		$this->extension_table = $extension_table; @@ -70,6 +69,14 @@ class phpbb_extension_manager  	}  	/** +	* Set migrator (get around circular reference) +	*/ +	public function set_migrator(phpbb_db_migrator $migrator) +	{ +		$this->migrator = $migrator; +	} + +	/**  	* Loads all extension information from the database  	*  	* @return null  | 
