Skip to content

Commit

Permalink
Add new OptimizeCommand.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Apr 1, 2015
1 parent 6a8d769 commit 782335f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
19 changes: 13 additions & 6 deletions src/CommandServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\ServiceProvider;
use Orchestra\View\Console\DetectCommand;
use Orchestra\View\Console\ActivateCommand;
use Orchestra\View\Console\OptimizeCommand;

class CommandServiceProvider extends ServiceProvider
{
Expand All @@ -20,21 +21,26 @@ class CommandServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bindShared('orchestra.view.command.detect', function ($app) {
$this->app->singleton('orchestra.view.command.activate', function ($app) {
$finder = $app['orchestra.theme.finder'];

return new DetectCommand($finder);
return new ActivateCommand($finder);
});

$this->app->bindShared('orchestra.view.command.activate', function ($app) {
$this->app->singleton('orchestra.view.command.detect', function ($app) {
$finder = $app['orchestra.theme.finder'];

return new ActivateCommand($finder);
return new DetectCommand($finder);
});

$this->app->singleton('orchestra.view.command.optimize', function ($app) {
return new OptimizeCommand();
});

$this->commands([
'orchestra.view.command.detect',
'orchestra.view.command.activate',
'orchestra.view.command.detect',
'orchestra.view.command.optimize',
]);
}

Expand All @@ -46,8 +52,9 @@ public function register()
public function provides()
{
return [
'orchestra.view.command.detect',
'orchestra.view.command.activate',
'orchestra.view.command.detect',
'orchestra.view.command.optimize',
];
}
}
2 changes: 1 addition & 1 deletion src/Console/ActivateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class ActivateCommand extends BaseCommand
class ActivateCommand extends Command
{
use ConfirmableTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/Console/BaseCommand.php → src/Console/Command.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php namespace Orchestra\View\Console;

use Illuminate\Console\Command;
use Illuminate\Console\Command as BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

abstract class BaseCommand extends Command
abstract class Command extends BaseCommand
{
/**
* Execute the console command.
Expand Down
2 changes: 1 addition & 1 deletion src/Console/DetectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Orchestra\View\Theme\Finder;
use Orchestra\View\Theme\Manifest;

class DetectCommand extends BaseCommand
class DetectCommand extends Command
{
/**
* Theme finder instance.
Expand Down
56 changes: 56 additions & 0 deletions src/Console/OptimizeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php namespace Orchestra\View\Console;

use InvalidArgumentException;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\Console\Command as BaseCommand;

class OptimizeCommand extends BaseCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'theme:optimize';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Pre-cache themes views in the application.';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->info('Compiling views');

$this->compileViews();
}

/**
* Compile all view files.
*
* @return void
*/
protected function compileViews()
{
foreach ($this->laravel['view']->getFinder()->getPaths() as $path) {
foreach ($this->laravel['files']->allFiles($path) as $file) {
try {
$engine = $this->laravel['view']->getEngineFromPath($file);
} catch (InvalidArgumentException $e) {
continue;
}

if ($engine instanceof CompilerEngine) {
$engine->getCompiler()->compile($file);
}
}
}
}
}

0 comments on commit 782335f

Please sign in to comment.