| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * SelectionConfigParameter.php | |
| 4 | + * | |
| 5 | + * The SelectionConfigParameter class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <alexanderschneider85@gmail.com> | |
| 10 | + * @copyright 2008-2017 Alexander Schneider | |
| 11 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 | |
| 12 | + * @version SVN: $id$ | |
| 13 | + * @link http://wordpress.org/extend/plugins/user-access-manager/ | |
| 14 | + */ | |
| 2 | 15 | |
| 3 | 16 | declare(strict_types=1); |
| 4 | 17 | |
| 5 | 18 | namespace UserAccessManager\Config; |
| @@ -5,24 +18,49 @@ | ||
| 5 | 18 | namespace UserAccessManager\Config; |
| 6 | 19 | |
| 7 | 20 | use Exception; |
| 8 | 21 | |
| 22 | +/** | |
| 23 | + * Class SelectionConfigParameter | |
| 24 | + * | |
| 25 | + * @package UserAccessManager\Config | |
| 26 | + */ | |
| 9 | 27 | class SelectionConfigParameter extends ConfigParameter |
| 10 | 28 | { |
| 11 | 29 | /** |
| 30 | + * @var array | |
| 31 | + */ | |
| 32 | + private $selections; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * SelectionConfigParameter constructor. | |
| 36 | + * @param string $id | |
| 37 | + * @param mixed $defaultValue | |
| 38 | + * @param array $selections | |
| 12 | 39 | * @throws Exception |
| 13 | 40 | */ |
| 14 | - public function __construct(string $id, mixed $defaultValue, private array $selections) | |
| 41 | + public function __construct(string $id, $defaultValue, array $selections) | |
| 15 | 42 | { |
| 43 | + $this->selections = $selections; | |
| 44 | + | |
| 16 | 45 | parent::__construct($id, $defaultValue); |
| 17 | 46 | } |
| 18 | 47 | |
| 19 | - public function isValidValue(mixed $value): bool | |
| 48 | + /** | |
| 49 | + * Checks if the value is part of the selection. | |
| 50 | + * @param mixed $value | |
| 51 | + * @return bool | |
| 52 | + */ | |
| 53 | + public function isValidValue($value): bool | |
| 20 | 54 | { |
| 21 | 55 | $map = array_flip($this->selections); |
| 22 | 56 | return (isset($map[$value]) === true); |
| 23 | 57 | } |
| 24 | 58 | |
| 59 | + /** | |
| 60 | + * Returns the available selections. | |
| 61 | + * @return array | |
| 62 | + */ | |
| 25 | 63 | public function getSelections(): array |
| 26 | 64 | { |
| 27 | 65 | return $this->selections; |
| 28 | 66 | } |