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\Concerns\CreatesMatchingTest;
6
use Illuminate\Console\GeneratorCommand;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
use Symfony\Component\Console\Input\InputOption;
9
 
10
#[AsCommand(name: 'make:notification')]
11
class NotificationMakeCommand extends GeneratorCommand
12
{
13
    use CreatesMatchingTest;
14
 
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'make:notification';
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 = 'make:notification';
32
 
33
    /**
34
     * The console command description.
35
     *
36
     * @var string
37
     */
38
    protected $description = 'Create a new notification class';
39
 
40
    /**
41
     * The type of class being generated.
42
     *
43
     * @var string
44
     */
45
    protected $type = 'Notification';
46
 
47
    /**
48
     * Execute the console command.
49
     *
50
     * @return void
51
     */
52
    public function handle()
53
    {
54
        if (parent::handle() === false && ! $this->option('force')) {
55
            return;
56
        }
57
 
58
        if ($this->option('markdown')) {
59
            $this->writeMarkdownTemplate();
60
        }
61
    }
62
 
63
    /**
64
     * Write the Markdown template for the mailable.
65
     *
66
     * @return void
67
     */
68
    protected function writeMarkdownTemplate()
69
    {
70
        $path = $this->viewPath(
71
            str_replace('.', '/', $this->option('markdown')).'.blade.php'
72
        );
73
 
74
        if (! $this->files->isDirectory(dirname($path))) {
75
            $this->files->makeDirectory(dirname($path), 0755, true);
76
        }
77
 
78
        $this->files->put($path, file_get_contents(__DIR__.'/stubs/markdown.stub'));
79
    }
80
 
81
    /**
82
     * Build the class with the given name.
83
     *
84
     * @param  string  $name
85
     * @return string
86
     */
87
    protected function buildClass($name)
88
    {
89
        $class = parent::buildClass($name);
90
 
91
        if ($this->option('markdown')) {
92
            $class = str_replace(['DummyView', '{{ view }}'], $this->option('markdown'), $class);
93
        }
94
 
95
        return $class;
96
    }
97
 
98
    /**
99
     * Get the stub file for the generator.
100
     *
101
     * @return string
102
     */
103
    protected function getStub()
104
    {
105
        return $this->option('markdown')
106
            ? $this->resolveStubPath('/stubs/markdown-notification.stub')
107
            : $this->resolveStubPath('/stubs/notification.stub');
108
    }
109
 
110
    /**
111
     * Resolve the fully-qualified path to the stub.
112
     *
113
     * @param  string  $stub
114
     * @return string
115
     */
116
    protected function resolveStubPath($stub)
117
    {
118
        return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
119
            ? $customPath
120
            : __DIR__.$stub;
121
    }
122
 
123
    /**
124
     * Get the default namespace for the class.
125
     *
126
     * @param  string  $rootNamespace
127
     * @return string
128
     */
129
    protected function getDefaultNamespace($rootNamespace)
130
    {
131
        return $rootNamespace.'\Notifications';
132
    }
133
 
134
    /**
135
     * Get the console command options.
136
     *
137
     * @return array
138
     */
139
    protected function getOptions()
140
    {
141
        return [
142
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the notification already exists'],
143
            ['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the notification'],
144
        ];
145
    }
146
}