diff --git a/src/Caffeinated/Modules/Handlers/Console/Commands/ModuleMakeHandler.php b/src/Caffeinated/Modules/Handlers/Console/Commands/ModuleMakeHandler.php index 1e556cb5..05a2bcdd 100644 --- a/src/Caffeinated/Modules/Handlers/Console/Commands/ModuleMakeHandler.php +++ b/src/Caffeinated/Modules/Handlers/Console/Commands/ModuleMakeHandler.php @@ -123,6 +123,8 @@ public function generate(Command $console) $console->info("Module [{$this->name}] has been created successfully."); + $this->optimize($console); + return true; } @@ -158,6 +160,16 @@ protected function generateFiles() } } + /** + * Optimize the framework for better performance. + * + * @return void + */ + protected function optimize(Command $console) + { + $console->call('optimize'); + } + /** * Generate .gitkeep files within generated folders. * diff --git a/src/Caffeinated/Modules/Modules.php b/src/Caffeinated/Modules/Modules.php index 1a824d0b..d6dab04b 100644 --- a/src/Caffeinated/Modules/Modules.php +++ b/src/Caffeinated/Modules/Modules.php @@ -36,21 +36,21 @@ public function register() { $modules = $this->repository->enabled(); - foreach ($modules as $module) { - $this->registerServiceProvider($module); - } + $modules->each(function($properties, $slug) { + $this->registerServiceProvider($properties); + }); } /** * Register the module service provider. * - * @param string $module + * @param string $properties * @return string * @throws \Caffeinated\Modules\Exception\FileMissingException */ - protected function registerServiceProvider($module) + protected function registerServiceProvider($properties) { - $module = studly_case($module['slug']); + $module = studly_case($properties['slug']); $file = $this->repository->getPath()."/{$module}/Providers/{$module}ServiceProvider.php"; $namespace = $this->repository->getNamespace().$module."\\Providers\\{$module}ServiceProvider"; diff --git a/src/Caffeinated/Modules/ModulesServiceProvider.php b/src/Caffeinated/Modules/ModulesServiceProvider.php index 493ee2fd..877159d9 100644 --- a/src/Caffeinated/Modules/ModulesServiceProvider.php +++ b/src/Caffeinated/Modules/ModulesServiceProvider.php @@ -8,7 +8,7 @@ class ModulesServiceProvider extends ServiceProvider /** * @var bool $defer Indicates if loading of the provider is deferred. */ - protected $defer = true; + protected $defer = false; /** * Boot the service provider. @@ -20,6 +20,8 @@ public function boot() $this->publishes([ __DIR__.'/../../config/modules.php' => config_path('modules.php'), ]); + + $this->app['modules']->register(); } /** @@ -44,10 +46,6 @@ public function register() return new \Caffeinated\Modules\Modules($app, $repository); }); - - $this->app->booting(function ($app) { - $app['modules']->register(); - }); } /** diff --git a/src/Caffeinated/Modules/Repositories/Local/ModuleRepository.php b/src/Caffeinated/Modules/Repositories/Local/ModuleRepository.php index 379fa7fe..dbc84232 100644 --- a/src/Caffeinated/Modules/Repositories/Local/ModuleRepository.php +++ b/src/Caffeinated/Modules/Repositories/Local/ModuleRepository.php @@ -12,13 +12,14 @@ class ModuleRepository extends Repository */ public function all() { - $modules = $this->getAllBasenames(); + $basenames = $this->getAllBasenames(); + $modules = collect(); - foreach ($modules as $key => $module) { - $modules[$key] = $this->getProperties($module); - } + $basenames->each(function($module, $key) use ($modules) { + $modules->put($module, $this->getProperties($module)); + }); - return collect($modules)->sortBy('order'); + return $modules->sortBy('order'); } /** @@ -48,7 +49,7 @@ public function where($key, $value) { $collection = $this->all(); - return $collection->where($key, $value)->all(); + return $collection->where($key, $value); } /** @@ -61,7 +62,7 @@ public function sortBy($key) { $collection = $this->all(); - return $collection->sortBy($key)->all(); + return $collection->sortBy($key); } /** @@ -74,7 +75,7 @@ public function sortByDesc($key) { $collection = $this->all(); - return $collection->sortByDesc($key)->all(); + return $collection->sortByDesc($key); } /** diff --git a/src/Caffeinated/Modules/Repositories/Repository.php b/src/Caffeinated/Modules/Repositories/Repository.php index 42200595..1f0c744f 100644 --- a/src/Caffeinated/Modules/Repositories/Repository.php +++ b/src/Caffeinated/Modules/Repositories/Repository.php @@ -41,13 +41,14 @@ public function __construct(Config $config, Filesystem $files) */ protected function getAllBasenames() { - $path = $this->getPath(); + $path = $this->getPath(); + $collection = collect($this->files->directories($path)); - if ($this->files->exists($path)) { - return array_map('basename', $this->files->directories($path)); - } + $basenames = $collection->map(function($item, $key) { + return basename($item); + }); - return array(); + return $basenames; } /**