Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Console;
4
 
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Finder\Finder;
10
use Symfony\Component\Finder\SplFileInfo;
11
 
12
#[AsCommand(name: 'view:cache')]
13
class ViewCacheCommand extends Command
14
{
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'view:cache';
21
 
22
    /**
23
     * The name of the console command.
24
     *
25
     * This name is used to identify the command during lazy loading.
26
     *
27
     * @var string|null
28
     *
29
     * @deprecated
30
     */
31
    protected static $defaultName = 'view:cache';
32
 
33
    /**
34
     * The console command description.
35
     *
36
     * @var string
37
     */
38
    protected $description = "Compile all of the application's Blade templates";
39
 
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $this->callSilent('view:clear');
48
 
49
        $this->paths()->each(function ($path) {
50
            $prefix = $this->output->isVeryVerbose() ? '<fg=yellow;options=bold>DIR</> ' : '';
51
 
52
            $this->components->task($prefix.$path, null, OutputInterface::VERBOSITY_VERBOSE);
53
 
54
            $this->compileViews($this->bladeFilesIn([$path]));
55
        });
56
 
57
        $this->newLine();
58
 
59
        $this->components->info('Blade templates cached successfully.');
60
    }
61
 
62
    /**
63
     * Compile the given view files.
64
     *
65
     * @param  \Illuminate\Support\Collection  $views
66
     * @return void
67
     */
68
    protected function compileViews(Collection $views)
69
    {
70
        $compiler = $this->laravel['view']->getEngineResolver()->resolve('blade')->getCompiler();
71
 
72
        $views->map(function (SplFileInfo $file) use ($compiler) {
73
            $this->components->task('    '.$file->getRelativePathname(), null, OutputInterface::VERBOSITY_VERY_VERBOSE);
74
 
75
            $compiler->compile($file->getRealPath());
76
        });
77
 
78
        if ($this->output->isVeryVerbose()) {
79
            $this->newLine();
80
        }
81
    }
82
 
83
    /**
84
     * Get the Blade files in the given path.
85
     *
86
     * @param  array  $paths
87
     * @return \Illuminate\Support\Collection
88
     */
89
    protected function bladeFilesIn(array $paths)
90
    {
91
        return collect(
92
            Finder::create()
93
                ->in($paths)
94
                ->exclude('vendor')
95
                ->name('*.blade.php')
96
                ->files()
97
        );
98
    }
99
 
100
    /**
101
     * Get all of the possible view paths.
102
     *
103
     * @return \Illuminate\Support\Collection
104
     */
105
    protected function paths()
106
    {
107
        $finder = $this->laravel['view']->getFinder();
108
 
109
        return collect($finder->getPaths())->merge(
110
            collect($finder->getHints())->flatten()
111
        );
112
    }
113
}