PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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
← All changes | src/Config/ConfigParameter.php +67 -18 2.3.14 → 2.1.11 View file →
@@ -1,50 +1,99 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * ConfigParameter.php
4 + *
5 + * The ConfigParameter class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\Config;
6 16
7 -use Exception;
8 -
17 +/**
18 + * Class ConfigParameter
19 + *
20 + * @package UserAccessManager\Config
21 + */
9 22 abstract class ConfigParameter implements ConfigParameterInterface
10 23 {
11 - protected mixed $defaultValue = null;
12 - protected mixed $value = null;
24 + /**
25 + * @var string
26 + */
27 + protected $id;
13 28
14 29 /**
15 - * @throws Exception
30 + * @var mixed
16 31 */
17 - public function __construct(
18 - protected string $id,
19 - mixed $defaultValue = null
20 - ) {
32 + protected $defaultValue = null;
33 +
34 + /**
35 + * @var mixed
36 + */
37 + protected $value = null;
38 +
39 + /**
40 + * ConfigParameter constructor.
41 + *
42 + * @param string $id
43 + * @param mixed $defaultValue
44 + *
45 + * @throws \Exception
46 + */
47 + public function __construct($id, $defaultValue = null)
48 + {
49 + $this->id = $id;
50 +
21 51 $this->validateValue($defaultValue);
22 52 $this->defaultValue = $defaultValue;
23 53 }
24 54
25 - public function getId(): string
55 + /**
56 + * Returns the id.
57 + *
58 + * @return string
59 + */
60 + public function getId()
26 61 {
27 62 return $this->id;
28 63 }
29 64
30 65 /**
31 - * @throws Exception
66 + * Checks the value type and throws an exception if the value isn't the required type.
67 + *
68 + * @param mixed $value
69 + *
70 + * @throws \Exception
32 71 */
33 - protected function validateValue($value): void
72 + protected function validateValue($value)
34 73 {
35 74 if ($this->isValidValue($value) === false) {
36 - throw new Exception("Wrong value '$value' type given for '$this->id'.'");
75 + throw new \Exception("Wrong value '{$value}' type given for '{$this->id}'.'");
37 76 }
38 77 }
39 78
40 - public function setValue(mixed $value): void
79 + /**
80 + * Sets the current value.
81 + *
82 + * @param mixed $value
83 + */
84 + public function setValue($value)
41 85 {
42 86 $this->isValidValue($value);
43 87 $this->value = $value;
44 88 }
45 89
46 - public function getValue(): mixed
90 + /**
91 + * Returns the current parameter value.
92 + *
93 + * @return mixed
94 + */
95 + public function getValue()
47 96 {
48 97 return ($this->value === null) ? $this->defaultValue : $this->value;
49 98 }
50 99 }