| 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 |
namespace UserAccessManager\Config; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class SelectionConfigParameter |
| 19 |
* |
| 20 |
* @package UserAccessManager\Config |
| 21 |
*/ |
| 22 |
class SelectionConfigParameter extends ConfigParameter |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
private $selections; |
| 28 |
|
| 29 |
/** |
| 30 |
* SelectionConfigParameter constructor. |
| 31 |
* |
| 32 |
* @param string $id |
| 33 |
* @param mixed $defaultValue |
| 34 |
* @param array $selections |
| 35 |
* |
| 36 |
* @throws \Exception |
| 37 |
*/ |
| 38 |
public function __construct($id, $defaultValue, array $selections) |
| 39 |
{ |
| 40 |
$this->selections = $selections; |
| 41 |
|
| 42 |
parent::__construct($id, $defaultValue); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Checks if the value is part of the selection. |
| 47 |
* |
| 48 |
* @param mixed $value |
| 49 |
* |
| 50 |
* @return bool |
| 51 |
*/ |
| 52 |
public function isValidValue($value) |
| 53 |
{ |
| 54 |
$map = array_flip($this->selections); |
| 55 |
return (isset($map[$value]) === true); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns the available selections. |
| 60 |
* |
| 61 |
* @return array |
| 62 |
*/ |
| 63 |
public function getSelections() |
| 64 |
{ |
| 65 |
return $this->selections; |
| 66 |
} |
| 67 |
} |
| 68 |
|