Skip to content

Commit

Permalink
add blade cache command
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 14, 2018
1 parent 82d8165 commit 9fd1273
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/Illuminate/Foundation/Console/BladeCacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class BladeCacheCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'blade:cache';

/**
* The console command description.
*
* @var string
*/
protected $description = "Compile all of the application's Blade templates";

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->paths()->each(function ($path) {
$this->compileViews($this->bladeFilesIn([$path]));
});

$this->info('Blade templates cached successfully!');
}

/**
* Compile the given view files.
*
* @param \Illuminate\Support\Collection $views
* @return void
*/
protected function compileViews(Collection $views)
{
$compiler = $this->laravel['blade.compiler'];

$views->map(function (SplFileInfo $file) use ($compiler) {
$compiler->compile($file->getRealPath());
});
}

/**
* Get the Blade files in the given path.
*
* @param array $paths
* @return \Illuminate\Support\Collection
*/
protected function bladeFilesIn(array $paths)
{
return collect(Finder::create()->
in($paths)

This comment has been minimized.

Copy link
@carusogabriel

carusogabriel Mar 15, 2018

Contributor

@taylorotwell Maybe wrong format?

->exclude('vendor')
->name('*.blade.php')->files());
}

/**
* Get all of the possible view paths.
*
* @return \Illuminate\Support\Collection
*/
protected function paths()
{
$finder = $this->laravel['view']->getFinder();

return collect($finder->getPaths())->merge(
collect($finder->getHints())->flatten()
);
}
}
14 changes: 14 additions & 0 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Illuminate\Session\Console\SessionTableCommand;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
use Illuminate\Foundation\Console\BladeCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Foundation\Console\ChannelMakeCommand;
Expand Down Expand Up @@ -83,6 +84,7 @@ class ArtisanServiceProvider extends ServiceProvider
* @var array
*/
protected $commands = [
'BladeCache' => 'command.blade.cache',
'CacheClear' => 'command.cache.clear',
'CacheForget' => 'command.cache.forget',
'ClearCompiled' => 'command.clear-compiled',
Expand Down Expand Up @@ -208,6 +210,18 @@ protected function registerAuthMakeCommand()
});
}

/**
* Register the command.
*
* @return void
*/
protected function registerBladeCacheCommand()
{
$this->app->singleton('command.blade.cache', function ($app) {
return new BladeCacheCommand;
});
}

/**
* Register the command.
*
Expand Down

0 comments on commit 9fd1273

Please sign in to comment.