@@ -34,16 +34,16 @@ class Packer implements IPacker
3434 private const HUGE = 4294967295 ;
3535
3636 private $ structuresLt = [
37- Relationship::class => [0x52 , 'packInteger ' , 'packInteger ' , 'packInteger ' , 'packString ' , 'packMap ' ],
38- Date::class => [0x44 , 'packInteger ' ],
39- Time::class => [0x54 , 'packInteger ' , 'packInteger ' ],
40- LocalTime::class => [0x74 , 'packInteger ' ],
41- DateTime::class => [0x46 , 'packInteger ' , 'packInteger ' , 'packInteger ' ],
42- DateTimeZoneId::class => [0x66 , 'packInteger ' , 'packInteger ' , 'packString ' ],
43- LocalDateTime::class => [0x64 , 'packInteger ' , 'packInteger ' ],
44- Duration::class => [0x45 , 'packInteger ' , 'packInteger ' , 'packInteger ' , 'packInteger ' ],
45- Point2D::class => [0x58 , 'packInteger ' , 'packFloat ' , 'packFloat ' ],
46- Point3D::class => [0x59 , 'packInteger ' , 'packFloat ' , 'packFloat ' , 'packFloat ' ]
37+ Relationship::class => [0x52 , 'id ' => ' packInteger ' , 'startNodeId ' => ' packInteger ' , 'endNodeId ' => ' packInteger ' , 'type ' => ' packString ' , ' properties ' => 'packMap ' ],
38+ Date::class => [0x44 , 'days ' => ' packInteger ' ],
39+ Time::class => [0x54 , 'nanoseconds ' => ' packInteger ' , ' tz_offset_seconds ' => 'packInteger ' ],
40+ LocalTime::class => [0x74 , 'nanoseconds ' => ' packInteger ' ],
41+ DateTime::class => [0x46 , 'seconds ' => ' packInteger ' , 'nanoseconds ' => ' packInteger ' , ' tz_offset_seconds ' => 'packInteger ' ],
42+ DateTimeZoneId::class => [0x66 , 'seconds ' => ' packInteger ' , 'nanoseconds ' => ' packInteger ' , ' tz_id ' => 'packString ' ],
43+ LocalDateTime::class => [0x64 , 'seconds ' => ' packInteger ' , ' nanoseconds ' => 'packInteger ' ],
44+ Duration::class => [0x45 , 'months ' => ' packInteger ' , 'days ' => ' packInteger ' , 'seconds ' => ' packInteger ' , ' nanoseconds ' => 'packInteger ' ],
45+ Point2D::class => [0x58 , 'srid ' => ' packInteger ' , 'x ' => ' packFloat ' , ' y ' => 'packFloat ' ],
46+ Point3D::class => [0x59 , 'srid ' => ' packInteger ' , 'x ' => ' packFloat ' , 'y ' => ' packFloat ' , ' z ' => 'packFloat ' ]
4747 ];
4848
4949 /**
@@ -257,24 +257,15 @@ private function packList(array $arr): string
257257 */
258258 private function packStructure (IStructure $ structure ): string
259259 {
260- $ reflection = new \ReflectionClass ($ structure );
261- $ properties = $ reflection ->getProperties ();
262- $ cnt = count ($ properties );
263-
264260 if (!array_key_exists (get_class ($ structure ), $ this ->structuresLt )) {
265261 throw new PackException ('Provided structure as parameter is not supported ' );
266262 }
267263
268264 $ arr = $ this ->structuresLt [get_class ($ structure )];
269- if (count ($ arr ) != $ cnt + 1 ) {
270- throw new PackException ('Invalid amount of structure properties ' );
271- }
272-
273- $ output = pack ('C ' , 0b10110000 | $ cnt );
274- $ output .= chr (array_shift ($ arr ));
275- foreach ($ arr as $ i => $ method ) {
276- $ properties [$ i ]->setAccessible (true );
277- $ output .= $ this ->{$ method }($ properties [$ i ]->getValue ($ structure ));
265+ $ signature = chr (array_shift ($ arr ));
266+ $ output = pack ('C ' , 0b10110000 | count ($ arr )) . $ signature ;
267+ foreach ($ arr as $ structureMethod => $ packerMethod ) {
268+ $ output .= $ this ->{$ packerMethod }($ structure ->{$ structureMethod }());
278269 }
279270
280271 return $ output ;
0 commit comments