1 | <?php |
||
12 | class Uuid |
||
13 | { |
||
14 | /** |
||
15 | * The current UUID value under consideration |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $value; |
||
20 | |||
21 | /** |
||
22 | * @var Format |
||
23 | */ |
||
24 | protected $format; |
||
25 | |||
26 | /** |
||
27 | * @var array<string,string> |
||
28 | */ |
||
29 | protected $fields; |
||
30 | |||
31 | /** |
||
32 | * @param string $value A UUID in any of the accepted formats |
||
33 | * @param Format $format The format of the UUID (will be validated) |
||
34 | */ |
||
35 | 8 | public function __construct($value, Format $format = null) |
|
45 | |||
46 | /** |
||
47 | * Parses the value into fields (according to format) |
||
48 | * |
||
49 | * @throws InvalidArgumentException |
||
50 | * @return void |
||
51 | */ |
||
52 | 6 | protected function parse() |
|
62 | |||
63 | /** |
||
64 | * @param string $name |
||
65 | * @return string |
||
66 | * @throws InvalidArgumentException |
||
67 | */ |
||
68 | 4 | public function getField($name) |
|
73 | |||
74 | /** |
||
75 | * @param string $name |
||
76 | * @param string $value |
||
77 | * @return void |
||
78 | * @throws InvalidArgumentException |
||
79 | */ |
||
80 | 2 | public function setField($name, $value) |
|
85 | |||
86 | /** |
||
87 | * Checks whether the UUID appears valid for the specified input format |
||
88 | * |
||
89 | * The input format is set as the second constructor parameter. This method |
||
90 | * will validate the $value passed to the constructor against the format. |
||
91 | * |
||
92 | * @return boolean |
||
93 | */ |
||
94 | 2 | public function isValid() |
|
98 | |||
99 | /** |
||
100 | * Converts the UUID to the specified format |
||
101 | * |
||
102 | * @param Format $format |
||
103 | * @return string |
||
104 | * @throws InvalidArgumentException |
||
105 | */ |
||
106 | 3 | public function toFormat(Format $format) |
|
111 | } |
||
112 |