diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/Icinga/Less/LightMode.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-a598b28402ead15d3701df32e198513e7b1f299c.tar.xz icingaweb2-a598b28402ead15d3701df32e198513e7b1f299c.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/Icinga/Less/LightMode.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/library/Icinga/Less/LightMode.php b/library/Icinga/Less/LightMode.php new file mode 100644 index 0000000..b4b72a0 --- /dev/null +++ b/library/Icinga/Less/LightMode.php @@ -0,0 +1,128 @@ +<?php +/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */ + +namespace Icinga\Less; + +use ArrayIterator; +use InvalidArgumentException; +use IteratorAggregate; +use Less_Environment; +use Traversable; + +/** + * Registry for light modes and the environments in which they are defined + */ +class LightMode implements IteratorAggregate +{ + /** @var array Mode environments as mode-environment pairs */ + protected $envs = []; + + /** @var array Assoc list of modes */ + protected $modes = []; + + /** @var array Mode selectors as mode-selector pairs */ + protected $selectors = []; + + /** + * @param string $mode + * + * @return $this + * + * @throws InvalidArgumentException If the mode already exists + */ + public function add($mode) + { + if (array_key_exists($mode, $this->modes)) { + throw new InvalidArgumentException("$mode already exists"); + } + + $this->modes[$mode] = true; + + return $this; + } + + /** + * @param string $mode + * + * @return Less_Environment + * + * @throws InvalidArgumentException If there is no environment for the given mode + */ + public function getEnv($mode) + { + if (! isset($this->envs[$mode])) { + throw new InvalidArgumentException("$mode does not exist"); + } + + return $this->envs[$mode]; + } + + /** + * @param string $mode + * @param Less_Environment $env + * + * @return $this + * + * @throws InvalidArgumentException If an environment for given the mode already exists + */ + public function setEnv($mode, Less_Environment $env) + { + if (array_key_exists($mode, $this->envs)) { + throw new InvalidArgumentException("$mode already exists"); + } + + $this->envs[$mode] = $env; + + return $this; + } + + /** + * @param string $mode + * + * @return bool + */ + public function hasSelector($mode) + { + return isset($this->selectors[$mode]); + } + + /** + * @param string $mode + * + * @return string + * + * @throws InvalidArgumentException If there is no selector for the given mode + */ + public function getSelector($mode) + { + if (! isset($this->selectors[$mode])) { + throw new InvalidArgumentException("$mode does not exist"); + } + + return $this->selectors[$mode]; + } + + /** + * @param string $mode + * @param string $selector + * + * @return $this + * + * @throws InvalidArgumentException If a selector for given the mode already exists + */ + public function setSelector($mode, $selector) + { + if (array_key_exists($mode, $this->selectors)) { + throw new InvalidArgumentException("$mode already exists"); + } + + $this->selectors[$mode] = $selector; + + return $this; + } + + public function getIterator(): Traversable + { + return new ArrayIterator(array_keys($this->modes)); + } +} |