2021-04-17 00:26:33 +02:00
|
|
|
<?php
|
2021-04-17 21:20:54 +02:00
|
|
|
namespace WapplerSystems\Meilisearch\System\Meilisearch;
|
2021-04-17 00:26:33 +02:00
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* This class provides static helper functions that are helpful during the result parsing for meilisearch.
|
2021-04-17 00:26:33 +02:00
|
|
|
*/
|
|
|
|
class ParsingUtil
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This method is used to covert a array structure with json.nl=flat to have it as return with json.nl=map.
|
|
|
|
*
|
|
|
|
* @param $options
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getMapArrayFromFlatArray(array $options): array
|
|
|
|
{
|
|
|
|
$keyValueMap = [];
|
|
|
|
$valueFromKeyNode = -1;
|
|
|
|
foreach($options as $key => $value) {
|
|
|
|
$isKeyNode = (($key % 2) == 0);
|
|
|
|
if ($isKeyNode) {
|
|
|
|
$valueFromKeyNode = $value;
|
|
|
|
} else {
|
|
|
|
if($valueFromKeyNode == -1) {
|
|
|
|
throw new \UnexpectedValueException('No optionValue before count value');
|
|
|
|
}
|
|
|
|
//we have a countNode
|
|
|
|
$keyValueMap[$valueFromKeyNode] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $keyValueMap;
|
|
|
|
}
|
|
|
|
}
|