Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding App::location() method to be able to obtain the defined path f…

…or a class
  • Loading branch information...
commit f8ab1d3c731cadfcff4433d7a0635c79471bcfba 1 parent 273125d
@lorenzo lorenzo authored
Showing with 23 additions and 0 deletions.
  1. +13 −0 lib/Cake/Core/App.php
  2. +10 −0 lib/Cake/Test/Case/Core/AppTest.php
View
13 lib/Cake/Core/App.php
@@ -588,6 +588,19 @@ public static function load($className) {
}
/**
+ * 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.
*
View
10 lib/Cake/Test/Case/Core/AppTest.php
@@ -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'));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.