*/ class StopWordParser { /** * Parse the meilisearch stopwords response from an json string to an array. * * @param string $jsonString * @return array */ public function parseJson($jsonString) { $stopWords = []; $decodedResponse = json_decode($jsonString); if (isset($decodedResponse->wordSet->managedList)) { $stopWords = (array)$decodedResponse->wordSet->managedList; } return $stopWords; } /** * @param string|array $stopWords * @return string * @throws \Apache_Meilisearch_InvalidArgumentException */ public function toJson($stopWords) { if (empty($stopWords)) { throw new \Apache_Meilisearch_InvalidArgumentException('Must provide stop word.'); } if (is_string($stopWords)) { $stopWords = [$stopWords]; } $stopWords = array_values($stopWords); return json_encode($stopWords); } }