29 lines
660 B
PHP
29 lines
660 B
PHP
<?php
|
|
|
|
namespace Mcnd\CLI\Option;
|
|
|
|
class KeyValueOption extends ParsedOption
|
|
{
|
|
protected array $values = [];
|
|
|
|
public function setValue(string $key, string $value) : void
|
|
{
|
|
$this->values[$key] = $value;
|
|
}
|
|
|
|
public function setRawValue(string $value) : void
|
|
{
|
|
if (! str_contains($value, '=')) {
|
|
throw new \RuntimeException(sprintf("A key=value notation was awaited, received %s instead", $value));
|
|
}
|
|
|
|
list($key, $value) = explode('=', trim($value), 2);
|
|
|
|
$this->setValue($key, $value);
|
|
}
|
|
|
|
public function getValue() : null|array
|
|
{
|
|
return $this->values ?: null;
|
|
}
|
|
} |