Skip to content

Commit

Permalink
Improve the Modules Service
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyCyborg committed Mar 24, 2017
1 parent b2a3e51 commit c7032e7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/Module/Console/ModuleOptimizeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Nova\Module\Console;

use Nova\Console\Command;


class ModuleOptimizeCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:optimize';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Optimize the module cache for better performance';

/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->info('Generating optimized module cache');

$this->nova['modules']->optimize();
}
}
16 changes: 15 additions & 1 deletion src/Module/Providers/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Nova\Module\Providers;

use Nova\Module\Console\ModuleListCommand;
use Nova\Module\Console\ModuleOptimizeCommand;

use Nova\Support\ServiceProvider;

Expand All @@ -16,7 +17,7 @@ class ConsoleServiceProvider extends ServiceProvider
*/
protected $defer = true;


/**
* Bootstrap the application services.
*/
Expand All @@ -32,6 +33,7 @@ public function register()
{
$commands = array(
'List',
'Optimize'
);

foreach ($commands as $command) {
Expand All @@ -50,4 +52,16 @@ protected function registerListCommand()

$this->commands('command.module.list');
}

/**
* Register the module:list command.
*/
protected function registerOptimizeCommand()
{
$this->app->singleton('command.module.optimize', function ($app) {
return new ModuleOptimizeCommand($app['modules']);
});

$this->commands('command.module.optimize');
}
}
12 changes: 12 additions & 0 deletions src/Module/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ public function getNamespace()
|
*/

/**
* Update cached repository of module information.
*
* @return bool
*/
public function optimize()
{
$modules = $this->getAllModules();

$this->writeCache($modules);
}

/**
* Get the contents of the cache file.
*
Expand Down

0 comments on commit c7032e7

Please sign in to comment.