Last active
December 11, 2015 22:09
-
-
Save edorian/4667851 to your computer and use it in GitHub Desktop.
simpler https://github.com/igorw/ilias/compare/autoload draft
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
edo@localhost ~/auto-all-the-loads $ tree && find . -type f -print -exec cat {} \; | |
. | |
|-- autoload.php | |
|-- index.php | |
`-- src | |
|-- A.php | |
`-- bar | |
|-- baz | |
| `-- B.php | |
`-- B.php | |
3 directories, 5 files | |
./src/A.php | |
<?php | |
namespace edo\foo; | |
class A {} | |
./src/bar/baz/B.php | |
<?php | |
namespace edo\foo\bar\baz; | |
class B {} | |
./src/bar/B.php | |
<?php | |
namespace edo\foo\bar; | |
class B {} | |
./index.php | |
<?php | |
namespace edo\foo; | |
require_once __DIR__ . '/autoload.php'; | |
$x = new A(); | |
$y = new \edo\foo\bar\B(); | |
$z = new \edo\foo\bar\baz\B(); | |
echo "Jojo"; | |
./autoload.php | |
<?php | |
spl_autoload_register(function($className) { | |
$prefix = 'edo\\foo\\'; | |
if (strncmp($prefix, $className, strlen($prefix)) === 0) { | |
require __DIR__ . '/src/' . str_replace('\\', '/', substr($className, strlen($prefix))) . '.php'; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
php index.php
string(38) "/home/edo/auto-all-the-loads/src/A.php"
string(42) "/home/edo/auto-all-the-loads/src/bar/B.php"
string(46) "/home/edo/auto-all-the-loads/src/bar/baz/B.php"