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

View File

@ -107,7 +107,10 @@ class ClassManifestTest extends SapphireTest {
}
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->manifestTests->getModules());
}

View File

@ -111,7 +111,10 @@ class NamespacedClassManifestTest extends SapphireTest {
}
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());
}
}