mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 22:38:52 +00:00
[feature/extension-manager] Make the cache variable name for extensions dynamic
Allows multiple instances to use cache simultaneously. PHPBB3-10323
This commit is contained in:
parent
bd1366d62d
commit
739e9eb58e
3 changed files with 17 additions and 10 deletions
|
@ -26,6 +26,7 @@ class phpbb_extension_finder
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $phpEx;
|
protected $phpEx;
|
||||||
|
protected $cache_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array An associative array, containing all search parameters set in
|
* @var array An associative array, containing all search parameters set in
|
||||||
|
@ -48,13 +49,16 @@ class phpbb_extension_finder
|
||||||
* @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_interface $cache A cache instance or null
|
* @param phpbb_cache_driver_interface $cache A cache instance or null
|
||||||
* @param string $phpEx php file extension
|
* @param string $phpEx php file extension
|
||||||
|
* @param string $cache_name The name of the cache variable, defaults to
|
||||||
|
* _ext_finder
|
||||||
*/
|
*/
|
||||||
public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $phpEx = '.php')
|
public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $phpEx = '.php', $cache_name = '_ext_finder')
|
||||||
{
|
{
|
||||||
$this->extension_manager = $extension_manager;
|
$this->extension_manager = $extension_manager;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->phpEx = $phpEx;
|
$this->phpEx = $phpEx;
|
||||||
|
$this->cache_name = $cache_name;
|
||||||
|
|
||||||
$this->query = array(
|
$this->query = array(
|
||||||
'default_path' => false,
|
'default_path' => false,
|
||||||
|
@ -66,7 +70,7 @@ class phpbb_extension_finder
|
||||||
'directory' => false,
|
'directory' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->cached_queries = ($this->cache) ? $this->cache->get('_ext_finder') : false;
|
$this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -284,7 +288,7 @@ class phpbb_extension_finder
|
||||||
if ($cache && $this->cache)
|
if ($cache && $this->cache)
|
||||||
{
|
{
|
||||||
$this->cached_queries[$query] = $files;
|
$this->cached_queries[$query] = $files;
|
||||||
$this->cache->put('_ext_finder', $this->cached_queries);
|
$this->cache->put($this->cache_name, $this->cached_queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $files;
|
return $files;
|
||||||
|
|
|
@ -27,6 +27,7 @@ class phpbb_extension_manager
|
||||||
protected $extensions;
|
protected $extensions;
|
||||||
protected $extension_table;
|
protected $extension_table;
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
|
protected $cache_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a manager and loads information from database
|
* Creates a manager and loads information from database
|
||||||
|
@ -36,16 +37,18 @@ class phpbb_extension_manager
|
||||||
* @param string $phpbb_root_path Path to the phpbb includes directory.
|
* @param string $phpbb_root_path Path to the phpbb includes directory.
|
||||||
* @param string $phpEx php file extension
|
* @param string $phpEx php file extension
|
||||||
* @param phpbb_cache_driver_interface $cache A cache instance or null
|
* @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(dbal $db, $extension_table, $phpbb_root_path, $phpEx = '.php', phpbb_cache_driver_interface $cache = null)
|
public function __construct(dbal $db, $extension_table, $phpbb_root_path, $phpEx = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')
|
||||||
{
|
{
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->phpEx = $phpEx;
|
$this->phpEx = $phpEx;
|
||||||
$this->extension_table = $extension_table;
|
$this->extension_table = $extension_table;
|
||||||
|
$this->cache_name = $cache_name;
|
||||||
|
|
||||||
$this->extensions = $this->cache->get('_ext');
|
$this->extensions = $this->cache->get($this->cache_name);
|
||||||
|
|
||||||
if ($this->extensions === false)
|
if ($this->extensions === false)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +78,7 @@ class phpbb_extension_manager
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($this->extensions);
|
ksort($this->extensions);
|
||||||
$this->cache->put('_ext', $this->extensions);
|
$this->cache->put($this->cache_name, $this->extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,6 +359,6 @@ class phpbb_extension_manager
|
||||||
*/
|
*/
|
||||||
public function get_finder()
|
public function get_finder()
|
||||||
{
|
{
|
||||||
return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx);
|
return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx, $this->cache_name . '_finder');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
public function test_get_classes_create_cache()
|
public function test_get_classes_create_cache()
|
||||||
{
|
{
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache);
|
$finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache, '.php', '_custom_cache_name');
|
||||||
$files = $finder->suffix('_class.php')->get_files();
|
$files = $finder->suffix('_class.php')->get_files();
|
||||||
|
|
||||||
sort($files);
|
sort($files);
|
||||||
|
@ -147,7 +147,7 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected_files, $files);
|
$this->assertEquals($expected_files, $files);
|
||||||
$cache->checkAssociativeVar($this, '_extension_finder', array(
|
$cache->checkAssociativeVar($this, '_custom_cache_name', array(
|
||||||
md5(serialize($query)) => $expected_files,
|
md5(serialize($query)) => $expected_files,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
);
|
);
|
||||||
|
|
||||||
$finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array(
|
$finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array(
|
||||||
'_extension_finder' => array(
|
'_ext_finder' => array(
|
||||||
md5(serialize($query)) => array('file_name'),
|
md5(serialize($query)) => array('file_name'),
|
||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
|
|
Loading…
Add table
Reference in a new issue