Файл: concrete5.7.5.6/concrete/src/Url/UrlImmutable.php
Строк: 126
<?php
namespace ConcreteCoreUrl;
use RuntimeException;
class UrlImmutable extends LeagueUrlUrlImmutable implements UrlInterface
{
public function setPortIfNecessary($port)
{
$clone = clone $this;
if (!$port) {
return $clone;
}
if (
($this->getScheme()->get() == 'http' && $port == '80') ||
($this->getScheme()->get() == 'https' && $port == '443')) {
return $clone;
}
$clone->port->set($port);
return $clone;
}
public static function createFromUrl($url, $trailing_slashes = self::TRAILING_SLASHES_AUTO)
{
if ($trailing_slashes === self::TRAILING_SLASHES_AUTO) {
$trailing_slashes = (bool) Config::get('concrete.seo.trailing_slash', false);
}
$trailing_slashes = (bool) $trailing_slashes;
$url = (string)$url;
$url = trim($url);
$original_url = $url;
$url = self::sanitizeUrl($url);
//if no valid scheme is found we add one
if (is_null($url)) {
throw new RuntimeException(
sprintf(
'The given URL: `%s` could not be parsed',
$original_url));
}
$components = @parse_url($url);
if (false === $components) {
throw new RuntimeException(
sprintf(
'The given URL: `%s` could not be parsed',
$original_url));
}
$components = array_merge(
array(
'scheme' => null,
'user' => null,
'pass' => null,
'host' => null,
'port' => null,
'path' => null,
'query' => null,
'fragment' => null,
),
$components);
$components = self::formatAuthComponent($components);
$components = self::formatPathComponent($components, $original_url);
return new static(
new LeagueUrlComponentsScheme($components['scheme']),
new LeagueUrlComponentsUser($components['user']),
new LeagueUrlComponentsPass($components['pass']),
new LeagueUrlComponentsHost($components['host']),
new LeagueUrlComponentsPort($components['port']),
new ConcreteCoreUrlComponentsPath($components['path'], $trailing_slashes),
new LeagueUrlComponentsQuery($components['query']),
new LeagueUrlComponentsFragment($components['fragment'])
);
}
}