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\Contracts\Console\Kernel as ConsoleKernelContract;
7
use Illuminate\Filesystem\Filesystem;
8
use LogicException;
9
use Symfony\Component\Console\Attribute\AsCommand;
10
use Throwable;
11
 
12
#[AsCommand(name: 'config:cache')]
13
class ConfigCacheCommand extends Command
14
{
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'config: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 = 'config:cache';
32
 
33
    /**
34
     * The console command description.
35
     *
36
     * @var string
37
     */
38
    protected $description = 'Create a cache file for faster configuration loading';
39
 
40
    /**
41
     * The filesystem instance.
42
     *
43
     * @var \Illuminate\Filesystem\Filesystem
44
     */
45
    protected $files;
46
 
47
    /**
48
     * Create a new config cache command instance.
49
     *
50
     * @param  \Illuminate\Filesystem\Filesystem  $files
51
     * @return void
52
     */
53
    public function __construct(Filesystem $files)
54
    {
55
        parent::__construct();
56
 
57
        $this->files = $files;
58
    }
59
 
60
    /**
61
     * Execute the console command.
62
     *
63
     * @return void
64
     *
65
     * @throws \LogicException
66
     */
67
    public function handle()
68
    {
69
        $this->callSilent('config:clear');
70
 
71
        $config = $this->getFreshConfiguration();
72
 
73
        $configPath = $this->laravel->getCachedConfigPath();
74
 
75
        $this->files->put(
76
            $configPath, '<?php return '.var_export($config, true).';'.PHP_EOL
77
        );
78
 
79
        try {
80
            require $configPath;
81
        } catch (Throwable $e) {
82
            $this->files->delete($configPath);
83
 
84
            throw new LogicException('Your configuration files are not serializable.', 0, $e);
85
        }
86
 
87
        $this->components->info('Configuration cached successfully.');
88
    }
89
 
90
    /**
91
     * Boot a fresh copy of the application configuration.
92
     *
93
     * @return array
94
     */
95
    protected function getFreshConfiguration()
96
    {
97
        $app = require $this->laravel->bootstrapPath().'/app.php';
98
 
99
        $app->useStoragePath($this->laravel->storagePath());
100
 
101
        $app->make(ConsoleKernelContract::class)->bootstrap();
102
 
103
        return $app['config']->all();
104
    }
105
}