/** * Converts a value from its database representation to its PHP representation * * @param mixed $value The value to convert * @param AbstractPlatform $platform The currently used database platform * * @return mixed * * @throws ConversionException When the conversion fails */ public function convertToPHPValue($value, AbstractPlatform $platform) { if (empty($value)) { return null; } if ($value instanceof Uri) { return $value; } try { $uri = Uri::parse($value); } catch (Exception $exception) { throw ConversionException::conversionFailed($value, static::TYPE_NAME); } return $uri; }
/** * Normalizes the query * * Sorts query by key and removes values without keys. * * @param string|null $query The query * * @return string|null * * @throws DomainException When the query is invalid */ protected static function normalizeQuery($query) { if (null === $query) { return null; } if ('' === $query) { return ''; } $parts = []; $order = []; // sort query params by key and remove missing keys foreach (explode('&', $query) as $param) { if ('' === $param || '=' === $param[0]) { continue; } $parts[] = $param; $kvp = explode('=', $param, 2); $order[] = $kvp[0]; } array_multisort($order, SORT_ASC, $parts); return parent::normalizeQuery(implode('&', $parts)); }
/** * Merges a base URI and relative path * * @link http://tools.ietf.org/html/rfc3986#section-5.2.3 * * @param Uri $baseUri The base Uri instance * @param string $relative The relative path * * @return string */ protected static function mergePaths(Uri $baseUri, string $relative) : string { $basePath = $baseUri->path(); if ($baseUri->authority() !== null && $basePath === '') { return sprintf('/%s', $relative); } $last = strrpos($basePath, '/'); if ($last !== false) { return sprintf('%s/%s', substr($basePath, 0, $last), $relative); } return $relative; }
/** * @expectedException Novuso\System\Exception\DomainException */ public function test_that_resolve_throws_exception_for_ref_with_first_seg_colon() { Uri::resolve('http://app.dev', '/seg:check/path'); }
/** * @expectedException \AssertionError */ public function test_that_compare_to_throws_exception_for_invalid_argument() { $uri = Uri::parse('https://www.google.com'); $uri->compareTo('https://www.google.com'); }