-
Notifications
You must be signed in to change notification settings - Fork 13
/
CommandInput.php
52 lines (43 loc) · 1.14 KB
/
CommandInput.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace OpenOnMake;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Input\ArgvInput;
class CommandInput
{
private ArgvInput $input;
private Collection $collection;
public function __construct(ArgvInput $input)
{
$this->input = $input;
$this->setCollection();
}
public function getCollection() : Collection
{
return $this->collection;
}
private function setCollection()
{
$this->collection = collect(explode(' ', $this->input));
}
/**
* First item in collection is comand string (index zero)
* Second item is Class Name w/without namespace (index one)
* Remaining items are just options
*
* @return void
*/
public function getOptions() : array
{
return $this->collection->slice(2)->all();
}
public function getClassNameOfNameArgument() : string
{
$exploded = explode('\\', $this->collection[1]);
$className = trim(array_pop($exploded), "'");
return $className;
}
public function hasOptions() : bool
{
return $this->collection->count() > 2;
}
}