notadd\vendor\notadd\framework\src\Module\ModuleManager.php
function getModules
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /** * Modules of list. * * @return \Illuminate\Support\Collection */ public function getModules() { if ( $this ->modules->isEmpty()) { if ( $this ->files->isDirectory( $this ->getModulePath())) { collect( $this ->files->directories( $this ->getModulePath()))->each( function ( $directory ) { if ( $this ->files->exists( $file = $directory . DIRECTORY_SEPARATOR . 'composer.json' )) { $package = new Collection(json_decode( $this ->files->get( $file ), true)); $identification = Arr::get( $package , 'name' ); $type = Arr::get( $package , 'type' ); if ( $type == 'notadd-module' && $identification ) { $provider = '' ; if ( $entries = data_get( $package , 'autoload.psr-4' )) { foreach ( $entries as $namespace => $entry ) { $provider = $namespace . 'ModuleServiceProvider' ; } } if ( $this ->files->exists( $autoload = $directory . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php' )) { $this ->files->requireOnce( $autoload ); } $authors = Arr::get( $package , 'authors' ); $description = Arr::get( $package , 'description' ); if ( class_exists ( $provider )) { $module = new Module( $identification ); $module ->setAuthor( $authors ); $module ->setDescription( $description ); $module ->setDirectory( $directory ); $module ->setEnabled( $this ->container->isInstalled() ? $this ->container->make( 'setting' )->get( 'module.' . $identification . '.enabled' , false) : false); $module ->setInstalled( $this ->container->isInstalled() ? $this ->container->make( 'setting' )->get( 'module.' . $identification . '.installed' , false) : false); $module ->setEntry( $provider ); if (method_exists( $provider , 'alias' )) { $module ->setAlias(call_user_func([ $provider , 'alias' ])); } else { $module ->setAlias([ $identification ]); } method_exists( $provider , 'description' ) && $module ->setDescription(call_user_func([ $provider , 'description' ])); method_exists( $provider , 'name' ) && $module ->setName(call_user_func([ $provider , 'name' ])); method_exists( $provider , 'script' ) && $module ->setScript(call_user_func([ $provider , 'script' ])); method_exists( $provider , 'stylesheet' ) && $module ->setStylesheet(call_user_func([ $provider , 'stylesheet' ])); method_exists( $provider , 'version' ) && $module ->setVersion(call_user_func([ $provider , 'version' ])); $this ->modules->put( $identification , $module ); } else { $this ->unloaded->put( $identification , [ 'authors' => $authors , 'description' => $description , 'directory' => $directory , 'identification' => $identification , 'provider' => $provider , ]); } } } }); } } return $this ->modules; } |
这个function 获取到所有的module
我想一定是系统初始化的时候初始化了每一个module 所以才能注册到module的route