PluginProbe
User Access Manager / 2.2.6
User Access Manager v2.2.6
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Config / SelectionConfigParameter.php

SelectionConfigParameter.php in User Access Manager 2.2.6, at src/Config/SelectionConfigParameter.php

68 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Config;
19
20 use Exception;
21
22 /**
23 * Class SelectionConfigParameter
24 *
25 * @package UserAccessManager\Config
26 */
27 class SelectionConfigParameter extends ConfigParameter
28 {
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
39 * @throws Exception
40 */
41 public function __construct(string $id, $defaultValue, array $selections)
42 {
43 $this->selections = $selections;
44
45 parent::__construct($id, $defaultValue);
46 }
47
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
54 {
55 $map = array_flip($this->selections);
56 return (isset($map[$value]) === true);
57 }
58
59 /**
60 * Returns the available selections.
61 * @return array
62 */
63 public function getSelections(): array
64 {
65 return $this->selections;
66 }
67 }
68