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\GeneratorCommand;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Input\InputOption;
8
 
9
#[AsCommand(name: 'make:rule')]
10
class RuleMakeCommand extends GeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'make:rule';
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 = 'make:rule';
29
 
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Create a new validation rule';
36
 
37
    /**
38
     * The type of class being generated.
39
     *
40
     * @var string
41
     */
42
    protected $type = 'Rule';
43
 
44
    /**
45
     * Build the class with the given name.
46
     *
47
     * @param  string  $name
48
     * @return string
49
     *
50
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
51
     */
52
    protected function buildClass($name)
53
    {
54
        return str_replace(
55
            '{{ ruleType }}',
56
            $this->option('implicit') ? 'ImplicitRule' : 'Rule',
57
            parent::buildClass($name)
58
        );
59
    }
60
 
61
    /**
62
     * Get the stub file for the generator.
63
     *
64
     * @return string
65
     */
66
    protected function getStub()
67
    {
68
        $stub = '/stubs/rule.stub';
69
 
70
        if ($this->option('invokable')) {
71
            $stub = '/stubs/rule.invokable.stub';
72
        }
73
 
74
        if ($this->option('implicit') && $this->option('invokable')) {
75
            $stub = str_replace('.stub', '.implicit.stub', $stub);
76
        }
77
 
78
        return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
79
            ? $customPath
80
            : __DIR__.$stub;
81
    }
82
 
83
    /**
84
     * Get the default namespace for the class.
85
     *
86
     * @param  string  $rootNamespace
87
     * @return string
88
     */
89
    protected function getDefaultNamespace($rootNamespace)
90
    {
91
        return $rootNamespace.'\Rules';
92
    }
93
 
94
    /**
95
     * Get the console command options.
96
     *
97
     * @return array
98
     */
99
    protected function getOptions()
100
    {
101
        return [
102
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the rule already exists'],
103
            ['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule'],
104
            ['invokable', null, InputOption::VALUE_NONE, 'Generate a single method, invokable rule class'],
105
        ];
106
    }
107
}