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')); }
/** * Return Low Resolution WMS URL from the Full resolution URL * * !! IMPORTANT !! * * It is supposed that WMS server provides a low resolution version * of the input layers. * * The low resolution layer should be named with the following convention * * <fullResolutionName>_lowres * * Example: * * LAYERS=mylayer for full resolution implies that low resolution * layer is named LAYERS=mylayer_lowres * * @param String $wms */ private function getLowResolutionUrl($wms) { /* * Convert full resolution WMS layer to KVP */ list($url, $kvpString) = explode('?', $wms, 2); $kvps = RestoUtil::queryStringToKvps($kvpString, true); if ($kvps['LAYERS']) { $kvps['LAYERS'] = $kvps['LAYERS'] . '_lowres'; } return $url . RestoUtil::kvpsToQueryString($kvps); }
/** * Reset user password * * @param string $email * @param string $password * @param string $url * * @return type */ private function resetUserPassword($email, $password, $url) { /* * Explod data['url'] into resourceUrl and queryString */ $pair = explode('?', $url); if (!isset($pair[1])) { RestoLogUtil::httpError(403); } /* * Only initiator of reset password can change its email */ $splittedUrl = explode('/', $pair[0]); if (strtolower(base64_decode($splittedUrl[count($splittedUrl) - 1])) !== $email) { RestoLogUtil::httpError(403); } $query = RestoUtil::queryStringToKvps($pair[1]); if (!isset($query['_tk']) || !$this->context->dbDriver->check(RestoDatabaseDriver::SHARED_LINK, array('resourceUrl' => $pair[0], 'token' => $query['_tk']))) { RestoLogUtil::httpError(403); } if ($this->context->dbDriver->get(RestoDatabaseDriver::USER_PASSWORD, array('email' => $email)) === str_repeat('*', 40)) { RestoLogUtil::httpError(3004); } if ($this->context->dbDriver->update(RestoDatabaseDriver::USER_PROFILE, array('profile' => array('email' => $email, 'password' => $password)))) { return RestoLogUtil::success('Password updated'); } else { RestoLogUtil::httpError(400); } }
/** * Rewrite URL with input query parameters * * @param string $url * @param array $newParams */ public static function updateUrl($url, $newParams = array()) { $existingParams = array(); $exploded = parse_url($url); if (isset($exploded['query'])) { $existingParams = RestoUtil::queryStringToKvps($exploded['query']); } return RestoUtil::baseUrl($exploded) . $exploded['path'] . RestoUtil::kvpsToQueryString(array_merge($existingParams, $newParams)); }