Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Console\Command;
13
 
14
use Symfony\Component\Console\Application;
15
use Symfony\Component\Console\Completion\CompletionInput;
16
use Symfony\Component\Console\Completion\CompletionSuggestions;
17
use Symfony\Component\Console\Completion\Suggestion;
18
use Symfony\Component\Console\Helper\HelperInterface;
19
use Symfony\Component\Console\Helper\HelperSet;
20
use Symfony\Component\Console\Input\InputDefinition;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
 
24
/**
25
 * @author Nicolas Grekas <p@tchwork.com>
26
 */
27
final class LazyCommand extends Command
28
{
29
    private \Closure|Command $command;
30
    private ?bool $isEnabled;
31
 
32
    public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true)
33
    {
34
        $this->setName($name)
35
            ->setAliases($aliases)
36
            ->setHidden($isHidden)
37
            ->setDescription($description);
38
 
39
        $this->command = $commandFactory;
40
        $this->isEnabled = $isEnabled;
41
    }
42
 
43
    public function ignoreValidationErrors(): void
44
    {
45
        $this->getCommand()->ignoreValidationErrors();
46
    }
47
 
48
    public function setApplication(Application $application = null): void
49
    {
50
        if (1 > \func_num_args()) {
51
            trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
52
        }
53
        if ($this->command instanceof parent) {
54
            $this->command->setApplication($application);
55
        }
56
 
57
        parent::setApplication($application);
58
    }
59
 
60
    public function setHelperSet(HelperSet $helperSet): void
61
    {
62
        if ($this->command instanceof parent) {
63
            $this->command->setHelperSet($helperSet);
64
        }
65
 
66
        parent::setHelperSet($helperSet);
67
    }
68
 
69
    public function isEnabled(): bool
70
    {
71
        return $this->isEnabled ?? $this->getCommand()->isEnabled();
72
    }
73
 
74
    public function run(InputInterface $input, OutputInterface $output): int
75
    {
76
        return $this->getCommand()->run($input, $output);
77
    }
78
 
79
    public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
80
    {
81
        $this->getCommand()->complete($input, $suggestions);
82
    }
83
 
84
    public function setCode(callable $code): static
85
    {
86
        $this->getCommand()->setCode($code);
87
 
88
        return $this;
89
    }
90
 
91
    /**
92
     * @internal
93
     */
94
    public function mergeApplicationDefinition(bool $mergeArgs = true): void
95
    {
96
        $this->getCommand()->mergeApplicationDefinition($mergeArgs);
97
    }
98
 
99
    public function setDefinition(array|InputDefinition $definition): static
100
    {
101
        $this->getCommand()->setDefinition($definition);
102
 
103
        return $this;
104
    }
105
 
106
    public function getDefinition(): InputDefinition
107
    {
108
        return $this->getCommand()->getDefinition();
109
    }
110
 
111
    public function getNativeDefinition(): InputDefinition
112
    {
113
        return $this->getCommand()->getNativeDefinition();
114
    }
115
 
116
    /**
117
     * @param array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion
118
     */
119
    public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static
120
    {
121
        $suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : [];
122
        $this->getCommand()->addArgument($name, $mode, $description, $default, $suggestedValues);
123
 
124
        return $this;
125
    }
126
 
127
    /**
128
     * @param array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion
129
     */
130
    public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static
131
    {
132
        $suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : [];
133
        $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default, $suggestedValues);
134
 
135
        return $this;
136
    }
137
 
138
    public function setProcessTitle(string $title): static
139
    {
140
        $this->getCommand()->setProcessTitle($title);
141
 
142
        return $this;
143
    }
144
 
145
    public function setHelp(string $help): static
146
    {
147
        $this->getCommand()->setHelp($help);
148
 
149
        return $this;
150
    }
151
 
152
    public function getHelp(): string
153
    {
154
        return $this->getCommand()->getHelp();
155
    }
156
 
157
    public function getProcessedHelp(): string
158
    {
159
        return $this->getCommand()->getProcessedHelp();
160
    }
161
 
162
    public function getSynopsis(bool $short = false): string
163
    {
164
        return $this->getCommand()->getSynopsis($short);
165
    }
166
 
167
    public function addUsage(string $usage): static
168
    {
169
        $this->getCommand()->addUsage($usage);
170
 
171
        return $this;
172
    }
173
 
174
    public function getUsages(): array
175
    {
176
        return $this->getCommand()->getUsages();
177
    }
178
 
179
    public function getHelper(string $name): HelperInterface
180
    {
181
        return $this->getCommand()->getHelper($name);
182
    }
183
 
184
    public function getCommand(): parent
185
    {
186
        if (!$this->command instanceof \Closure) {
187
            return $this->command;
188
        }
189
 
190
        $command = $this->command = ($this->command)();
191
        $command->setApplication($this->getApplication());
192
 
193
        if (null !== $this->getHelperSet()) {
194
            $command->setHelperSet($this->getHelperSet());
195
        }
196
 
197
        $command->setName($this->getName())
198
            ->setAliases($this->getAliases())
199
            ->setHidden($this->isHidden())
200
            ->setDescription($this->getDescription());
201
 
202
        // Will throw if the command is not correctly initialized.
203
        $command->getDefinition();
204
 
205
        return $command;
206
    }
207
}