public function test() { $this->initContext(); $this->assertEquals(false, RestoUtil::UUIDv5('toto', 'toto')); $this->assertEquals('tototototiti', RestoUtil::superImplode('toto', array('toto', 'titi', null))); $this->assertEquals('http://localhost/titi/toto/tata.format?huhu=tty.json', RestoUtil::updateUrlFormat('http://localhost/titi/toto/tata?huhu=tty.json', 'format')); $this->assertEquals('http://localhost/tata.format?huhu=tty.json', RestoUtil::updateUrlFormat('http://localhost/tata.json?huhu=tty.json', 'format')); $this->assertEquals('1977-01-01T00:00:00Z', RestoUtil::toISO8601('1977')); $this->assertEquals('1977-02-01T00:00:00Z', RestoUtil::toISO8601('1977-02')); $this->assertEquals('1977-02-10T00:00:00Z', RestoUtil::toISO8601('1977-02-10')); $this->assertEquals('1977-02-10T12:11:30Z', RestoUtil::toISO8601('1977-02-10T12:11:30Z')); $this->assertEquals(array('toto', 'titi', 'tata', 'tet', ' tifi ', 'cdd'), RestoUtil::splitString('toto"titi"tata tet" tifi "cdd')); $this->assertEquals(false, RestoUtil::isUrl(null)); $this->assertEquals(false, RestoUtil::isUrl('tokijhfomqzcdna')); $this->assertEquals(true, RestoUtil::isUrl('http://tititit.com/foiherfoh')); $this->assertEquals(null, RestoUtil::sanitize(null)); $this->assertEquals(array('tototot', 'tydsnc'), RestoUtil::sanitize(array('tototot', 'tydsnc'))); $this->assertEquals('ogfdrhefvdjsncosd', RestoUtil::sanitize('ogfdrhefvdjsncosd')); $this->assertEquals('', RestoUtil::kvpsToQueryString('ogfdrhefvdjsncosd')); $this->assertEquals('?&toto=ttiti&frfr=trtr', RestoUtil::kvpsToQueryString(array('toto' => 'ttiti', 'frfr' => 'trtr'))); $this->assertEquals('?&toto=ttiti&frfr=trtr&arr[]=titi&arr[]=toto', RestoUtil::kvpsToQueryString(array('toto' => 'ttiti', 'frfr' => 'trtr', 'arr' => array('toto', 'titi')))); $this->assertEquals(array('totot_tiiti_titi' => ''), RestoUtil::queryStringToKvps('totot tiiti titi')); }
/** * * Explode query into normalized array of words * * In order : * - replace "," and ";" characters by space * - transliterate query string afterward (i.e. all words in lowercase without accent) * - split remaining query - split each terms with (" " character) * - add a space between numeric value and '%' character * * @param string $query * @return array */ private function queryToWords($query) { $rawWords = RestoUtil::splitString($this->escapeMultiwords($this->context->dbDriver->normalize($this->removePrefixes(str_replace(array(',', ';'), ' ', $query))))); $words = array(); for ($i = 0, $ii = count($rawWords); $i < $ii; $i++) { $term = trim($rawWords[$i]); if ($term === '') { continue; } $splitted = explode('%', $term); if (count($splitted) === 2 && is_numeric($splitted[0])) { $words[] = $splitted[0]; $words[] = '%'; } else { $words[] = $rawWords[$i]; } } return $words; }
/** * Prepare SQL query for keywords- i.e. searchTerms * * !! IMPORTANT NOTE !! * * Searches are done on the array 'hashes' column * * @param RestoModel $model * @param string $filterName * @param array $requestParams * @param boolean $exclusion * @return type */ private function prepareFilterQuery_keywords($model, $filterName, $requestParams, $exclusion) { $terms = array(); $splitted = RestoUtil::splitString($requestParams[$filterName]); $filters = array('with' => array(), 'without' => array()); /* * Process each searchTerms * * Note: replace geohash: by hash: (see rocket) */ for ($i = 0, $l = count($splitted); $i < $l; $i++) { $terms = array_merge($this->processSearchTerms(str_replace('geohash:', 'hash:', $splitted[$i]), $filters, $model, $filterName, $exclusion)); } return join(' AND ', array_merge($terms, $this->mergeHashesFilters($model->getDbKey($model->searchFilters[$filterName]['key']), $filters))); }