ENHANCEMENT Added ClassInfo::classes_for_folder()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80641 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-06-30 22:08:59 +00:00
parent ca4ec1af03
commit 8ae9db13c0
2 changed files with 41 additions and 0 deletions

View File

@ -175,6 +175,9 @@ class ClassInfo {
* Get all classes contained in a file. * Get all classes contained in a file.
* @uses ManifestBuilder * @uses ManifestBuilder
* *
* @todo Doesn't return additional classes that only begin
* with the filename, and have additional naming separated through underscores.
*
* @param string $filePath Path to a PHP file (absolute or relative to webroot) * @param string $filePath Path to a PHP file (absolute or relative to webroot)
* @return array * @return array
*/ */
@ -190,6 +193,27 @@ class ClassInfo {
return $matchedClasses; return $matchedClasses;
} }
/**
* Returns all classes contained in a certain folder.
*
* @todo Doesn't return additional classes that only begin
* with the filename, and have additional naming separated through underscores.
*
* @param string $folderPath Relative or absolute folder path
* @return array Array of class names
*/
static function classes_for_folder($folderPath) {
$absFolderPath = Director::getAbsFile($folderPath);
global $_CLASS_MANIFEST;
$matchedClasses = array();
foreach($_CLASS_MANIFEST as $class => $compareFilePath) {
if(stripos($compareFilePath, $absFolderPath) === 0) $matchedClasses[] = $class;
}
return $matchedClasses;
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// DEPRECATED // DEPRECATED

View File

@ -17,6 +17,23 @@ class ClassInfoTest extends SapphireTest {
); );
} }
function testClassesForFolder() {
//$baseFolder = Director::baseFolder() . '/' . SAPPHIRE_DIR . '/tests/_ClassInfoTest';
//$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
$classes = ClassInfo::classes_for_folder('sapphire/tests');
$this->assertContains(
'ClassInfoTest',
$classes,
'ClassInfo::classes_for_folder() returns classes matching the filename'
);
// $this->assertContains(
// 'ClassInfoTest_BaseClass',
// $classes,
// 'ClassInfo::classes_for_folder() returns additional classes not matching the filename'
// );
}
} }
class ClassInfoTest_BaseClass { class ClassInfoTest_BaseClass {