FIX: _config/ directories are now correctly detected as modules (fixes #1762)

DO NOT MERGE: to be reviewed. Only i18n & Deprecation classes use
->getModules() as far as I can see. Given that the method still simply
returns an array of modulename => modulepath, I don't think it's really
an API change
This commit is contained in:
Loz Calver 2013-04-17 12:14:30 +01:00
parent 2523dfbe95
commit 0384369acb
5 changed files with 26 additions and 5 deletions

View File

@ -15,6 +15,7 @@
class SS_ClassManifest { class SS_ClassManifest {
const CONF_FILE = '_config.php'; const CONF_FILE = '_config.php';
const CONF_DIR = '_config';
protected $base; protected $base;
protected $tests; protected $tests;
@ -28,6 +29,7 @@ class SS_ClassManifest {
protected $interfaces = array(); protected $interfaces = array();
protected $implementors = array(); protected $implementors = array();
protected $configs = array(); protected $configs = array();
protected $configDirs = array();
/** /**
* @return TokenisedRegularExpression * @return TokenisedRegularExpression
@ -128,6 +130,7 @@ class SS_ClassManifest {
$this->interfaces = $data['interfaces']; $this->interfaces = $data['interfaces'];
$this->implementors = $data['implementors']; $this->implementors = $data['implementors'];
$this->configs = $data['configs']; $this->configs = $data['configs'];
$this->configDirs = $data['configDirs'];
} else { } else {
$this->regenerate($cache); $this->regenerate($cache);
} }
@ -254,6 +257,10 @@ class SS_ClassManifest {
foreach($this->configs as $configPath) { foreach($this->configs as $configPath) {
$modules[basename(dirname($configPath))] = dirname($configPath); $modules[basename(dirname($configPath))] = dirname($configPath);
} }
foreach($this->configDirs as $configDir) {
$path = preg_replace('/\/_config$/', '', dirname($configDir));
$modules[basename($path)] = $path;
}
return $modules; return $modules;
} }
@ -265,7 +272,7 @@ class SS_ClassManifest {
public function regenerate($cache = true) { public function regenerate($cache = true) {
$reset = array( $reset = array(
'classes', 'roots', 'children', 'descendants', 'interfaces', 'classes', 'roots', 'children', 'descendants', 'interfaces',
'implementors', 'configs' 'implementors', 'configs', 'configDirs'
); );
// Reset the manifest so stale info doesn't cause errors. // Reset the manifest so stale info doesn't cause errors.
@ -278,7 +285,8 @@ class SS_ClassManifest {
'name_regex' => '/^(_config.php|[^_].*\.php)$/', 'name_regex' => '/^(_config.php|[^_].*\.php)$/',
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'), 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
'ignore_tests' => !$this->tests, 'ignore_tests' => !$this->tests,
'file_callback' => array($this, 'handleFile') 'file_callback' => array($this, 'handleFile'),
'dir_callback' => array($this, 'handleDir')
)); ));
$finder->find($this->base); $finder->find($this->base);
@ -292,12 +300,19 @@ class SS_ClassManifest {
'descendants' => $this->descendants, 'descendants' => $this->descendants,
'interfaces' => $this->interfaces, 'interfaces' => $this->interfaces,
'implementors' => $this->implementors, 'implementors' => $this->implementors,
'configs' => $this->configs 'configs' => $this->configs,
'configDirs' => $this->configDirs
); );
$this->cache->save($data, $this->cacheKey); $this->cache->save($data, $this->cacheKey);
} }
} }
public function handleDir($basename, $pathname, $depth) {
if ($basename == self::CONF_DIR) {
$this->configDirs[] = $pathname;
}
}
public function handleFile($basename, $pathname, $depth) { public function handleFile($basename, $pathname, $depth) {
if ($basename == self::CONF_FILE) { if ($basename == self::CONF_FILE) {
$this->configs[] = $pathname; $this->configs[] = $pathname;

View File

@ -107,7 +107,10 @@ class ClassManifestTest extends SapphireTest {
} }
public function testGetModules() { public function testGetModules() {
$expect = array("module" => "{$this->base}/module"); $expect = array(
"module" => "{$this->base}/module",
"moduleb" => "{$this->base}/moduleb"
);
$this->assertEquals($expect, $this->manifest->getModules()); $this->assertEquals($expect, $this->manifest->getModules());
$this->assertEquals($expect, $this->manifestTests->getModules()); $this->assertEquals($expect, $this->manifestTests->getModules());
} }

View File

@ -111,7 +111,10 @@ class NamespacedClassManifestTest extends SapphireTest {
} }
public function testGetModules() { public function testGetModules() {
$expect = array("module" => "{$this->base}/module"); $expect = array(
"module" => "{$this->base}/module",
"moduleb" => "{$this->base}/moduleb"
);
$this->assertEquals($expect, $this->manifest->getModules()); $this->assertEquals($expect, $this->manifest->getModules());
} }
} }