-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82d8165
commit 9fd1273
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
->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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@taylorotwell Maybe wrong format?