|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Lenevor Framework |
|
5
|
|
|
* |
|
6
|
|
|
* LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the new BSD license that is bundled |
|
9
|
|
|
* with this package in the file license.md. |
|
10
|
|
|
* It is also available through the world-wide-web at this URL: |
|
11
|
|
|
* https://lenevor.com/license |
|
12
|
|
|
* If you did not receive a copy of the license and are unable to |
|
13
|
|
|
* obtain it through the world-wide-web, please send an email |
|
14
|
|
|
* to [email protected] so we can send you a copy immediately. |
|
15
|
|
|
* |
|
16
|
|
|
* @package Lenevor |
|
17
|
|
|
* @subpackage Base |
|
18
|
|
|
* @link https://lenevor.com |
|
19
|
|
|
* @copyright Copyright (c) 2019 - 2023 Alexander Campo <[email protected]> |
|
20
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Syscodes\Components\Console\Description; |
|
24
|
|
|
|
|
25
|
|
|
use InvalidArgumentException; |
|
26
|
|
|
use Syscodes\Components\Console\Application; |
|
27
|
|
|
use Syscodes\Components\Console\Command\Command; |
|
28
|
|
|
use Syscodes\Components\Console\Input\InputOption; |
|
29
|
|
|
use Syscodes\Components\Console\Input\InputArgument; |
|
30
|
|
|
use Syscodes\Components\Console\Input\InputDefinition; |
|
31
|
|
|
use Syscodes\Components\Contracts\Console\Output\Output as OutputInterface; |
|
32
|
|
|
use Syscodes\Components\Contracts\Console\Description\Descriptor as DescriptorInterface; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* This class allows all console description variables to be displayed. |
|
36
|
|
|
*/ |
|
37
|
|
|
abstract class Descriptor implements DescriptorInterface |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* The ouput command for console. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \Syscodes\Components\Contracts\Console\Output\Output $output |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $output; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Describes the type of input, output and command for console. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Syscodes\Components\Contracts\Console\Output\Output $output |
|
50
|
|
|
* @param object $object |
|
51
|
|
|
* @param array $options |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function describe(OutputInterface $output, object $object, array $options = []): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->output = $output; |
|
58
|
|
|
|
|
59
|
|
|
match (true) { |
|
60
|
|
|
$object instanceof InputArgument => $this->describeArgument($object, $options), |
|
|
|
|
|
|
61
|
|
|
$object instanceof InputOption => $this->describeOption($object, $options), |
|
|
|
|
|
|
62
|
|
|
$object instanceof InputDefinition => $this->describeDefinition($object, $options), |
|
|
|
|
|
|
63
|
|
|
$object instanceof Command => $this->describeCommand($object, $options), |
|
|
|
|
|
|
64
|
|
|
$object instanceof Application => $this->describeApplication($object, $options), |
|
|
|
|
|
|
65
|
|
|
default => throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object))), |
|
66
|
|
|
}; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Writes a message to the output. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $message The message to output |
|
73
|
|
|
* @param bool $option The option of bitmask |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function write(string $message, bool $option = false) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->output->write($message, false, $option ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Describes an InputArgument instance. |
|
84
|
|
|
* |
|
85
|
|
|
* @param \Syscodes\Components\Console\Input\InputArgument $argument The argument implemented |
|
86
|
|
|
* @param array $options The options of the console |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
abstract protected function describeArgument(InputArgument $argument, array $options = []); |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Describes an InputOption instance. |
|
94
|
|
|
* |
|
95
|
|
|
* @param \Syscodes\Components\Console\Input\InputOption $option The option implemented |
|
96
|
|
|
* @param array $options The options of the console |
|
97
|
|
|
* |
|
98
|
|
|
* @return void |
|
99
|
|
|
*/ |
|
100
|
|
|
abstract protected function describeOption(InputOption $option, array $options = []); |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Describes an InputDefinition instance. |
|
104
|
|
|
* |
|
105
|
|
|
* @param \Syscodes\Components\Console\Input\InputDefinition $definition The definition implemented |
|
106
|
|
|
* @param array $options The options of the console |
|
107
|
|
|
* |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
abstract protected function describeDefinition(InputDefinition $definition, array $options = []); |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Describes an Command instance. |
|
114
|
|
|
* |
|
115
|
|
|
* @param \Syscodes\Components\Console\Command\Command $command The command implemented |
|
116
|
|
|
* @param array $options The options of the console |
|
117
|
|
|
* |
|
118
|
|
|
* @return void |
|
119
|
|
|
*/ |
|
120
|
|
|
abstract protected function describeCommand(Command $command, array $options = []); |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Describes an Application instance. |
|
124
|
|
|
* |
|
125
|
|
|
* @param \Syscodes\Components\Console\Application $application The application implemented |
|
126
|
|
|
* @param array $options The options of the console |
|
127
|
|
|
* |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
|
|
abstract protected function describeApplication(Application $application, array $options = []); |
|
131
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.