1 | <?php |
||
15 | class Argument |
||
16 | { |
||
17 | /** |
||
18 | * The name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name; |
||
23 | |||
24 | /** |
||
25 | * The value. |
||
26 | * |
||
27 | * @var mixed |
||
28 | */ |
||
29 | protected $value; |
||
30 | |||
31 | /** |
||
32 | * Create argument object. |
||
33 | * |
||
34 | * @param string $name |
||
35 | * @param mixed $value |
||
36 | */ |
||
37 | 12 | public function __construct($name, $value = null) |
|
42 | |||
43 | /** |
||
44 | * Create argument object from string. |
||
45 | * |
||
46 | * @param string $argument |
||
47 | * |
||
48 | * @return $this |
||
49 | */ |
||
50 | 4 | public static function fromString($argument) |
|
51 | { |
||
52 | 4 | $argument = explode('=', $argument, 2); |
|
53 | 4 | $instance = new static(array_shift($argument)); |
|
54 | |||
55 | 4 | if (count($argument) > 0) { |
|
56 | 2 | $instance->setValue(array_shift($argument)); |
|
57 | 1 | } |
|
58 | |||
59 | 4 | return $instance; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Return argument object as string. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 4 | public function toString() |
|
75 | |||
76 | /** |
||
77 | * Get name. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 12 | public function getName() |
|
85 | |||
86 | /** |
||
87 | * Return whether the argument has a value. |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 4 | public function hasValue() |
|
95 | |||
96 | /** |
||
97 | * Get value. |
||
98 | * |
||
99 | * @return mixed |
||
100 | */ |
||
101 | 10 | public function getValue() |
|
105 | |||
106 | /** |
||
107 | * Set value. |
||
108 | * |
||
109 | * @param mixed $value |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | 2 | public function setValue($value) |
|
119 | } |
||
120 |