Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul M. Jones
committed
Nov 21, 2012
1 parent
b59833a
commit 922aaa5
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
<?php | |||
spl_autoload_register(function($class) { | |||
|
|||
// split the class into namespace parts | |||
$parts = explode('\\', $class); | |||
if (count($parts) == 1) { | |||
return; | |||
} | |||
|
|||
// the eventual filename | |||
$file = implode(DIRECTORY_SEPARATOR, $parts) . '.php'; | |||
|
|||
// the package dir for the class | |||
$dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . "{$parts[0]}.{$parts[1]}"; | |||
|
|||
// look for a package src file | |||
$tmp = $dir . DIRECTORY_SEPARATOR . 'src'. DIRECTORY_SEPARATOR . $file; | |||
if (is_readable($tmp)) { | |||
require_once $tmp; | |||
return; | |||
} | |||
|
|||
// look in the include-path | |||
$dirs = explode(PATH_SEPARATOR, get_include_path()); | |||
foreach ($dirs as $dir) { | |||
$tmp = $dir . DIRECTORY_SEPARATOR . $file; | |||
if (is_readable($tmp)) { | |||
require_once $tmp; | |||
return; | |||
} | |||
} | |||
}); |