Plugins
6 months ago
Option.php
9 months ago
Options.php
9 months ago
OptionsPlugin.php
9 months ago
Options.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\ColumnOptions; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Options |
| 7 | { |
| 8 | private array $options; |
| 9 | public function __construct(\IAWP\ColumnOptions\OptionsPlugin $options_plugin) |
| 10 | { |
| 11 | $this->options = $options_plugin->get_options(); |
| 12 | } |
| 13 | /** |
| 14 | * @return Option[] |
| 15 | */ |
| 16 | public function all() : array |
| 17 | { |
| 18 | return $this->options; |
| 19 | } |
| 20 | public function contains($option_id) : ?bool |
| 21 | { |
| 22 | return $this->find_by_id($option_id) !== null; |
| 23 | } |
| 24 | public function label_for($option_id) : ?string |
| 25 | { |
| 26 | $option = $this->find_by_id($option_id); |
| 27 | if (!$option) { |
| 28 | return null; |
| 29 | } |
| 30 | return $option->label; |
| 31 | } |
| 32 | private function find_by_id($option_id) : ?\IAWP\ColumnOptions\Option |
| 33 | { |
| 34 | foreach ($this->options as $option) { |
| 35 | // Don't make strict |
| 36 | if ($option->id == $option_id) { |
| 37 | return $option; |
| 38 | } |
| 39 | } |
| 40 | return null; |
| 41 | } |
| 42 | } |
| 43 |