本文整理汇总了PHP中Zend\Uri\Uri::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::normalize方法的具体用法?PHP Uri::normalize怎么用?PHP Uri::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Uri
的用法示例。
在下文中一共展示了Uri::normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRedirect
public function getRedirect($urlString, $stayLocal = true, $preserveHttps = true)
{
/**
* Check that the URL has the correct format expected of a valid HTTP
* or HTTPS URL. If so, normalize the URL.
*/
$valid = false;
$url = new Uri();
try {
$url->parse($urlString);
if ($url->isValid() && $url->isAbsolute()) {
$url->normalize();
$valid = true;
}
} catch (\Exception $e) {
}
if (false === $valid) {
throw new Exception\InvalidArgumentException("Given value was not a valid absolute HTTP(S) URL: " . $url);
}
/**
* Make sure we don't redirect from HTTPS to HTTP unless flagged by
* the user. Using a Strict-Transport-Security header helps too!
*/
if (true === (bool) $preserveHttps && HttpsDetector::isHttpsRequest()) {
if (!$this->isHttps($url)) {
throw new Exception\InvalidArgumentException("Given value was not a HTTPS URL as expected: " . $url);
}
}
/**
* Check if the URL meets the local host restriction unless disabled
*/
if (true === $stayLocal && !$this->isLocal($url)) {
throw new Exception\InvalidArgumentException("Given value was not a local HTTP(S) URL: " . $url);
}
/**
* Check if the URL host exists on a whitelist of allowed hosts
*/
$whitelist = $this->getWhitelist();
if (!empty($whitelist) && !$this->isWhitelisted($url)) {
throw new Exception\InvalidArgumentException("Given value was not a whitelisted URL as expected: " . $url);
}
/**
* Get URL string after URL encoding checks and return a Location header
* object.
*/
$header = new Header\Location(array('url' => $url->toString(), 'status_code' => 302));
return $header;
}
示例2: testNormalizeUrl
/**
* Test normalizing URLs
*
* @param string $orig
* @param string $expected
* @dataProvider normalizedUrlsProvider
*/
public function testNormalizeUrl($orig, $expected)
{
$url = new Uri($orig);
$this->assertEquals($expected, $url->normalize()->toString());
}
示例3: normalize
/**
* @return Uri
*/
public function normalize()
{
parent::normalize();
$this->fragment = static::normalizeFragment($this->fragment);
if (!$this->isAbsolute() && !$this->path && !$this->query && null === $this->fragment) {
$this->fragment = '';
}
return $this;
}
示例4: normalize
/**
* Normalize the URI
*
* @return \Zend\Uri\Uri
*/
public function normalize()
{
$this->uri->normalize();
return $this;
}