Skip to content

Instantly share code, notes, and snippets.

@pounard
Created March 16, 2016 13:13
Show Gist options
  • Save pounard/80d957dba47d915b6a78 to your computer and use it in GitHub Desktop.
Save pounard/80d957dba47d915b6a78 to your computer and use it in GitHub Desktop.
# mon_module/
# ma_library/src/Toto.php <- namespace de ma library, par exmple Ma\Library\Toto
# mon_module.module
# Dans mon_module.module, genre en haut:
spl_autoload_register(function ($class) {
$parts = explode('\\', $class);
if ('Ma' === $parts[0] && 'Library' === $parts[1]) {
array_shift($parts); // enleve 'Ma'
array_shift($parts); // enleve 'Library'
$file = __DIR__ . '/ma_library/src/' . implode('/', $parts) . '.php';
if (file_exists($file)) {
return include_once $file;
}
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment