Last active
September 29, 2023 21:27
-
-
Save mingalevme/04702bb7e5e361448cbe44cb7b3895d5 to your computer and use it in GitHub Desktop.
Revisions
-
mingalevme renamed this gist
Aug 7, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ class GoogleMapsQueryArgsDeserializer { public static function deserialize(string $input): array { -
mingalevme created this gist
Aug 7, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ class GoogleMapsParamDeserializer { public static function deserialize(string $input): array { $params = explode('!', trim($input, '!')); foreach ($params as $i => $param) { $params[$i] = urldecode($param); } return static::decode($params); } protected static function decode(array $params): array { $data = []; for ($i=0; $i<count($params); $i++) { $param = $params[$i]; if (preg_match('/^(\d+)m(\d+)/', $param, $matches)) { $id = intval($matches[1]); $length = intval($matches[2]); $data[$id] = static::decode(array_slice($params, $i+1, $length)); $i = $i + $length; } elseif (preg_match('/^(\d+)([fdibesuv])(.*)$/', $param, $matches)) { $id = intval($matches[1]); $type = $matches[2]; $value = $matches[3]; if ($type === 'i' || $type === 'e' || $type === 'u') { $data[$id] = intval($value); } elseif ($type === 'f') { $data[$id] = floatval($value); } elseif ($type === 'd') { $data[$id] = doubleval($value); } elseif ($type === 'b') { $data[$id] = boolval($value); } elseif ($type === 's' || $type === 'v') { $data[$id] = strval($value); } } else { throw new \RuntimeException('Unknown param format: ' . $param); } } return $data; } }