LippertComponents /
Blend
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: joshgulledge |
||
| 5 | * Date: 10/26/18 |
||
| 6 | * Time: 11:56 AM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace LCI\Blend\Helpers\TVInput; |
||
| 10 | |||
| 11 | |||
| 12 | class OptionValues |
||
| 13 | { |
||
| 14 | protected $options = []; |
||
| 15 | |||
| 16 | protected $separator = '||'; |
||
| 17 | |||
| 18 | protected $value_separator = '=='; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * OptionValues constructor. |
||
| 22 | * @param string $separator ~ the separator between items |
||
| 23 | * @param string $value_separator ~ the separator between label and value |
||
| 24 | */ |
||
| 25 | public function __construct(string $separator='||', string $value_separator='==') |
||
| 26 | { |
||
| 27 | $this->separator = $separator; |
||
| 28 | $this->value_separator = $value_separator; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public function toString() |
||
| 35 | { |
||
| 36 | $string = ''; |
||
| 37 | foreach ($this->options as $label => $value) { |
||
| 38 | if (!empty($string)) { |
||
| 39 | $string .= $this->separator; |
||
| 40 | } |
||
| 41 | $string .= $label . $this->value_separator . $value; |
||
| 42 | } |
||
| 43 | |||
| 44 | return $string; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | public function getOptions(): array |
||
| 51 | { |
||
| 52 | return $this->options; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $label |
||
| 57 | * @param null $value |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 58 | * @return $this |
||
| 59 | */ |
||
| 60 | public function setOption(string $label, $value=null): self |
||
| 61 | { |
||
| 62 | if (is_null($value)) { |
||
|
0 ignored issues
–
show
|
|||
| 63 | $value = $label; |
||
| 64 | } |
||
| 65 | $this->options[$label] = $value; |
||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The __toString method allows a class to decide how it will react when it is converted to a string. |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | * @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
||
| 74 | */ |
||
| 75 | public function __toString() |
||
| 76 | { |
||
| 77 | return $this->toString(); |
||
| 78 | } |
||
| 79 | } |