Created
November 1, 2016 06:40
-
-
Save prinsss/d7eb791b346e0521f838e269d8e87bd3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| public function boot(PluginManager $plugins) | |
| { | |
| // store paths of class files of plugins | |
| $src_paths = []; | |
| foreach ($plugins->getPlugins() as $plugin) { | |
| $src_paths[$plugin->getNameSpace()] = $plugin->getPath()."/src"; | |
| } | |
| $this->registerClassAutoloader($src_paths); | |
| // call bootstrappers here | |
| } | |
| /** | |
| * Register class autoloader for plugins. | |
| * | |
| * @return void | |
| */ | |
| protected function registerClassAutoloader($paths) | |
| { | |
| spl_autoload_register(function ($class) use ($paths) { | |
| // traverse in registered plugin paths | |
| foreach ((array) array_keys($paths) as $namespace) { | |
| if ($namespace != '' && mb_strpos($class, $namespace) === 0) { | |
| // parse real file path | |
| $path = $paths[$namespace].Str::replaceFirst($namespace, '', $class).".php"; | |
| $path = str_replace('\\', '/', $path); | |
| if (file_exists($path)) { | |
| // include class file if it exists | |
| include $path; | |
| } | |
| } | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment