| 1 | <?php |
||
| 19 | abstract class BaseIdentifier implements Identifier |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $value; |
||
| 25 | |||
| 26 | 49 | private function __construct($value) |
|
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $value |
||
| 33 | * @return static |
||
| 34 | * @throws InvalidIdentifierValueException |
||
| 35 | */ |
||
| 36 | 52 | public static function create($value) |
|
| 37 | { |
||
| 38 | 52 | if (!is_string($value)) { |
|
| 39 | 1 | throw new InvalidIdentifierValueException('Identifier value must be of type string'); |
|
| 40 | } |
||
| 41 | |||
| 42 | 51 | if ($value === '') { |
|
| 43 | 1 | throw new InvalidIdentifierValueException('Identifier must not be empty'); |
|
| 44 | } |
||
| 45 | |||
| 46 | 51 | static::validate($value); |
|
| 47 | |||
| 48 | 49 | return new static($value); |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $value |
||
| 53 | * @throws InvalidIdentifierValueException |
||
| 54 | */ |
||
| 55 | protected static function validate($value) |
||
| 58 | |||
| 59 | 49 | public function getValue() |
|
| 63 | |||
| 64 | 24 | public function __toString() |
|
| 68 | } |
||
| 69 |