Permalink
Browse files

add blade cache command

  • Loading branch information...
taylorotwell committed Mar 14, 2018
1 parent 82d8165 commit 9fd1273ad79a46bb3aa006129109c6bc72766e4b
@@ -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.

@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()
);
}
}
@@ -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;
@@ -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',
@@ -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.
*

0 comments on commit 9fd1273

Please sign in to comment.