[feature/extension-manager] Support extensions in subdirectories of ext/

PHPBB3-10323
This commit is contained in:
Nils Adermann 2011-10-14 01:30:50 +02:00
parent f53892c838
commit 4fb9f2101d
6 changed files with 28 additions and 22 deletions

View file

@ -94,7 +94,9 @@ class phpbb_extension_manager
*/
public function get_extension_path($name, $phpbb_relative = false)
{
return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . basename($name) . '/';
$name = str_replace('.', '', $name);
return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . $name . '/';
}
/**
@ -106,7 +108,7 @@ class phpbb_extension_manager
*/
public function get_extension($name)
{
$extension_class_name = 'phpbb_ext_' . $name . '_ext';
$extension_class_name = 'phpbb_ext_' . str_replace('/', '_', $name) . '_ext';
if (class_exists($extension_class_name))
{
@ -292,13 +294,17 @@ class phpbb_extension_manager
{
$available = array();
$iterator = new DirectoryIterator($this->phpbb_root_path . 'ext/');
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/'));
foreach ($iterator as $file_info)
{
$path = $this->phpbb_root_path . 'ext/' . $file_info->getBasename() . '/';
if (!$file_info->isDot() && $file_info->isDir() && file_exists($path))
if ($file_info->isFile() && $file_info->getFilename() == 'ext' . $this->phpEx)
{
$available[$file_info->getBasename()] = $path;
$ext_name = $iterator->getInnerIterator()->getSubPath();
$ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name);
$available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/';
}
}
ksort($available);

View file

@ -1,5 +0,0 @@
<?php
class phpbb_ext_moo_feature_class
{
}

View file

@ -1,6 +1,6 @@
<?php
class phpbb_ext_moo_ext extends phpbb_extension_base
class phpbb_ext_vendor_moo_ext extends phpbb_extension_base
{
static public $purged;

View file

@ -0,0 +1,5 @@
<?php
class phpbb_ext_vendor_moo_feature_class
{
}

View file

@ -8,7 +8,7 @@
<value>1</value>
</row>
<row>
<value>moo</value>
<value>vendor/moo</value>
<value>0</value>
</row>
</table>

View file

@ -9,7 +9,7 @@
require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/ext/bar/ext.php';
require_once dirname(__FILE__) . '/ext/moo/ext.php';
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php';
class phpbb_extension_manager_test extends phpbb_database_test_case
{
@ -36,7 +36,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
public function test_available()
{
$this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_available()));
$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available()));
}
public function test_enabled()
@ -46,7 +46,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
public function test_configured()
{
$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
}
public function test_enable()
@ -56,7 +56,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
$this->extension_manager->enable('bar');
$this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_configured()));
$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
$this->assertEquals(4, phpbb_ext_bar_ext::$state);
}
@ -66,20 +66,20 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
$this->extension_manager->disable('foo');
$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
}
public function test_purge()
{
phpbb_ext_moo_ext::$purged = false;
phpbb_ext_vendor_moo_ext::$purged = false;
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
$this->extension_manager->purge('moo');
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
$this->extension_manager->purge('vendor/moo');
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured()));
$this->assertTrue(phpbb_ext_moo_ext::$purged);
$this->assertTrue(phpbb_ext_vendor_moo_ext::$purged);
}
public function test_enabled_no_cache()