| 1 | <?php |
||
| 7 | class Identifier |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var int|null |
||
| 11 | */ |
||
| 12 | private $id; |
||
| 13 | |||
| 14 | 13 | public function __construct($id, $is_required = true) |
|
| 15 | { |
||
| 16 | 13 | static $empty_values = [null, false, 0, '0', '']; |
|
| 17 | |||
| 18 | 13 | if (in_array($id, $empty_values, true) && !$is_required) { |
|
| 19 | 3 | $id = null; |
|
| 20 | 3 | } else { |
|
| 21 | $options = [ |
||
| 22 | 10 | 'flags' => \FILTER_REQUIRE_SCALAR, |
|
| 23 | 'options' => [ |
||
| 24 | 10 | 'min_range' => 1, |
|
| 25 | 10 | ], |
|
| 26 | 10 | ]; |
|
| 27 | |||
| 28 | 10 | if (filter_var($id, \FILTER_VALIDATE_INT, $options) === false) { |
|
| 29 | 7 | throw new InvalidArgumentException('Value must be a valid identifier'); |
|
| 30 | } |
||
| 31 | |||
| 32 | 3 | $id = (int) $id; |
|
| 33 | } |
||
| 34 | |||
| 35 | 6 | $this->id = $id; |
|
| 36 | 6 | } |
|
| 37 | |||
| 38 | 6 | public function value() |
|
| 42 | } |
||
| 43 |