Skip to content

Commit

Permalink
Update autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
baikunz committed Apr 10, 2013
1 parent ad008d3 commit 411647f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
* @see https://wiki.php.net/rfc/splclassloader#example_implementation
*/
spl_autoload_register(function($className) {
$package = 'Shuble\\Slurpy';
$className = ltrim($className, '\\');
if (0 === strpos($className, $package)) {
$fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
if (is_file($fileName)) {
require $fileName;
if (0 != strpos($className, 'Shuble\\Slurpy')) {
return false;
}
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
if (is_file($fileName)) {
require $fileName;

return true;
}
return true;
}

return false;
Expand Down

0 comments on commit 411647f

Please sign in to comment.