mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
ca4ec1af03
commit
8ae9db13c0
@ -175,6 +175,9 @@ class ClassInfo {
|
||||
* Get all classes contained in a file.
|
||||
* @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)
|
||||
* @return array
|
||||
*/
|
||||
@ -190,6 +193,27 @@ class ClassInfo {
|
||||
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
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user