1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Artisanize\Input; |
4
|
|
|
|
5
|
|
|
abstract class Input |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Input. |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $input; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Original input string. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $original; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Input name. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Input description. |
30
|
|
|
* |
31
|
|
|
* @var null|string |
32
|
|
|
*/ |
33
|
|
|
protected $description; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Array of input modes to apply. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $modeArray = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Argument mode. |
44
|
|
|
* |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
protected $mode = 0; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Construct. |
51
|
|
|
* |
52
|
|
|
* @param string $input |
53
|
|
|
*/ |
54
|
|
|
public function __construct($input) |
55
|
|
|
{ |
56
|
|
|
$this->input = $input; |
57
|
|
|
$this->original = $input; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Parse the set input string. |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
abstract public function parse(); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the input attributes. |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
abstract public function getAttributes(); |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set array modeArray value if value contains *. |
76
|
|
|
* |
77
|
|
|
* @param string $constant |
78
|
|
|
* |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
|
|
protected function setArray($constant) |
82
|
|
|
{ |
83
|
|
|
if (strpos($this->input, '*') !== false) { |
84
|
|
|
$this->modeArray[] = $constant; |
85
|
|
|
|
86
|
|
|
$this->input = str_replace('*', '', $this->input); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Parse an argument/option description. |
94
|
|
|
* |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
|
|
protected function setDescription() |
98
|
|
|
{ |
99
|
|
|
if (strpos($this->input, ':') !== false) { |
100
|
|
|
$inputArray = array_map('trim', explode(':', $this->input)); |
101
|
|
|
|
102
|
|
|
$this->input = $inputArray[0]; |
103
|
|
|
|
104
|
|
|
$this->description = $inputArray[1]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Calculate the mode score. |
112
|
|
|
* |
113
|
|
|
* @param string $class |
114
|
|
|
* |
115
|
|
|
* @return $this |
116
|
|
|
*/ |
117
|
|
|
protected function calculateMode($class) |
118
|
|
|
{ |
119
|
|
|
foreach ($this->modeArray as $constant) { |
120
|
|
|
$this->mode = $this->mode | constant($class.'::'.$constant); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set the input name as the input value. |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
protected function setName() |
132
|
|
|
{ |
133
|
|
|
$this->name = $this->input; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|