Skip to content

Commit

Permalink
Adding App::location() method to be able to obtain the defined path f…
Browse files Browse the repository at this point in the history
…or a class
  • Loading branch information
lorenzo committed Jul 12, 2011
1 parent 273125d commit f8ab1d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Cake/Core/App.php
Expand Up @@ -587,6 +587,19 @@ public static function load($className) {
return false;
}

/**
* Returns the package name where a class was defined to be located at
*
* @param string $className name of the class to obtain the package name from
* @return string package name or null if not declared
*/
public static function location($className) {
if (!empty(self::$__classMap[$className])) {
return self::$__classMap[$className];
}
return null;
}

/**
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
* not construct any classes contained in the files. It will only find and require() the file.
Expand Down
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/Core/AppTest.php
Expand Up @@ -736,4 +736,14 @@ public function testLoadClassInLibs() {
App::uses('TestUtilityClass', 'Utility');
$this->assertTrue(class_exists('CustomLibClass'));
}

/**
* Tests that App::location() returns the defined path for a class
*
* @return void
*/
public function testClassLocation() {
App::uses('MyCustomClass', 'MyPackage/Name');
$this->assertEquals('MyPackage/Name', App::location('MyCustomClass'));
}
}

0 comments on commit f8ab1d3

Please sign in to comment.