1 | <?php |
||
17 | class EntityIdValue extends DataValueObject { |
||
18 | |||
19 | private $entityId; |
||
20 | |||
21 | public function __construct( EntityId $entityId ) { |
||
24 | |||
25 | /** |
||
26 | * @see Serializable::serialize |
||
27 | * |
||
28 | * @since 0.5 |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | public function serialize() { |
||
38 | |||
39 | /** |
||
40 | * This method gets the numeric id from the serialization. |
||
41 | * It makes assumptions we do not want to make about the id format, |
||
42 | * though cannot be removed until we ditch the "numeric id" part |
||
43 | * from the serialization. |
||
44 | * |
||
45 | * @return float Numeric id as a whole number. Can not be int because of 32-bit PHP. |
||
46 | */ |
||
47 | private function getNumericId() { |
||
48 | return floatval( substr( $this->entityId->getSerialization(), 1 ) ); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @see Serializable::unserialize |
||
53 | * |
||
54 | * @since 0.5 |
||
55 | * |
||
56 | * @param string $serialized |
||
57 | * |
||
58 | * @throws IllegalValueException |
||
59 | */ |
||
60 | public function unserialize( $serialized ) { |
||
61 | list( $entityType, $numericId ) = json_decode( $serialized ); |
||
62 | |||
63 | try { |
||
64 | $entityId = LegacyIdInterpreter::newIdFromTypeAndNumber( $entityType, $numericId ); |
||
65 | } catch ( InvalidArgumentException $ex ) { |
||
66 | throw new IllegalValueException( 'Invalid EntityIdValue serialization.' ); |
||
67 | } |
||
68 | |||
69 | $this->__construct( $entityId ); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @see DataValue::getType |
||
74 | * |
||
75 | * @since 0.5 |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public static function getType() { |
||
82 | |||
83 | /** |
||
84 | * @see DataValue::getSortKey |
||
85 | * |
||
86 | * @since 0.5 |
||
87 | * |
||
88 | * @return string|float|int |
||
89 | */ |
||
90 | public function getSortKey() { |
||
93 | |||
94 | /** |
||
95 | * @see DataValue::getValue |
||
96 | * |
||
97 | * @since 0.5 |
||
98 | * |
||
99 | * @return self |
||
100 | */ |
||
101 | public function getValue() { |
||
104 | |||
105 | /** |
||
106 | * @since 0.5 |
||
107 | * |
||
108 | * @return EntityId |
||
109 | */ |
||
110 | public function getEntityId() { |
||
113 | |||
114 | /** |
||
115 | * @see DataValue::getArrayValue |
||
116 | * |
||
117 | * @since 0.5 |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getArrayValue() { |
||
128 | |||
129 | /** |
||
130 | * Constructs a new instance of the DataValue from the provided data. |
||
131 | * This can round-trip with |
||
132 | * @see getArrayValue |
||
133 | * |
||
134 | * @since 0.5 |
||
135 | * |
||
136 | * @param mixed $data |
||
137 | * |
||
138 | * @throws IllegalValueException |
||
139 | * @return self |
||
140 | */ |
||
141 | public static function newFromArray( $data ) { |
||
156 | |||
157 | /** |
||
158 | * @param string $entityType |
||
159 | * @param int|float|string $numericId |
||
160 | * |
||
161 | * @throws IllegalValueException |
||
162 | * @return self |
||
163 | */ |
||
164 | private static function newIdFromTypeAndNumber( $entityType, $numericId ) { |
||
171 | |||
172 | } |
||
173 |