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\Foundation\Support\Providers\EventServiceProvider;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
 
9
#[AsCommand(name: 'event:cache')]
10
class EventCacheCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'event:cache';
18
 
19
    /**
20
     * The name of the console command.
21
     *
22
     * This name is used to identify the command during lazy loading.
23
     *
24
     * @var string|null
25
     *
26
     * @deprecated
27
     */
28
    protected static $defaultName = 'event:cache';
29
 
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = "Discover and cache the application's events and listeners";
36
 
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $this->callSilent('event:clear');
45
 
46
        file_put_contents(
47
            $this->laravel->getCachedEventsPath(),
48
            '<?php return '.var_export($this->getEvents(), true).';'
49
        );
50
 
51
        $this->components->info('Events cached successfully.');
52
    }
53
 
54
    /**
55
     * Get all of the events and listeners configured for the application.
56
     *
57
     * @return array
58
     */
59
    protected function getEvents()
60
    {
61
        $events = [];
62
 
63
        foreach ($this->laravel->getProviders(EventServiceProvider::class) as $provider) {
64
            $providerEvents = array_merge_recursive($provider->shouldDiscoverEvents() ? $provider->discoverEvents() : [], $provider->listens());
65
 
66
            $events[get_class($provider)] = $providerEvents;
67
        }
68
 
69
        return $events;
70
    }
71
}