Skip to content

Commit

Permalink
Added an option to get the filename from a class name
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Apr 16, 2015
1 parent 08e6763 commit 3af5a25
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@

class Autoload {

private static $declaredClasses = array();
private static $declaredInterfaces = array();
private static $loadedClasses = array();
private static $loadedFiles = array();

public static function load($class)
{
if (empty(self::$declaredClasses) === true) {
self::$declaredClasses = get_declared_classes();
self::$declaredInterfaces = get_declared_interfaces();
}

$ds = DIRECTORY_SEPARATOR;
$path = null;

Expand Down Expand Up @@ -50,6 +44,7 @@ public static function loadFile($path)
}

self::$loadedClasses[$path] = $className;
self::$loadedFiles[$className] = $path;
return self::$loadedClasses[$path];
}

Expand All @@ -62,6 +57,15 @@ public static function getLoadedClassName($file)
return self::$loadedClasses[$file];
}

public static function getLoadedFileName($class)
{
if (isset(self::$loadedFiles[$class]) === false) {
throw new \Exception("Cannot get file name for $class; class has not been included");
}

return self::$loadedFiles[$class];
}

}

spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);

0 comments on commit 3af5a25

Please sign in to comment.