Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'zf2/master' into feature/doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 203 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendframework/zend-uri",
"description": "Zend\\Uri component",
"description": "a component that aids in manipulating and validating \u00bb Uniform Resource Identifiers (URIs)",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
Expand All @@ -9,11 +9,11 @@
"homepage": "https://github.com/zendframework/zend-uri",
"autoload": {
"psr-4": {
"Zend\\Uri\\": "src/"
"Zend\\Uri": "src/"
}
},
"require": {
"php": ">=5.3.23",
"php": ">=5.3.3",
"zendframework/zend-escaper": "self.version",
"zendframework/zend-validator": "self.version"
},
Expand All @@ -23,14 +23,14 @@
"dev-develop": "2.5-dev"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
},
"autoload-dev": {
"psr-4": {
"ZendTest\\Uri\\": "test/"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
}
}
2 changes: 0 additions & 2 deletions src/Exception/ExceptionInterface.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ExceptionInterface
{}
Empty file modified src/Exception/InvalidArgumentException.php
100755 → 100644
Empty file.
2 changes: 0 additions & 2 deletions src/Exception/InvalidUriException.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class InvalidUriException extends InvalidArgumentException implements ExceptionInterface
{}
2 changes: 0 additions & 2 deletions src/Exception/InvalidUriPartException.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @category Zend
* @package Zend_Uri
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class InvalidUriPartException extends InvalidArgumentException
{
Expand Down
22 changes: 0 additions & 22 deletions src/Exception/InvalidUriTypeException.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/File.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class File extends Uri
{
Expand Down
2 changes: 0 additions & 2 deletions src/Http.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Http extends Uri
{
Expand Down
6 changes: 2 additions & 4 deletions src/Mailto.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Zend\Uri;

use Zend\Validator\ValidatorInterface,
Zend\Validator\EmailAddress as EmailValidator;
use Zend\Validator\EmailAddress as EmailValidator;
use Zend\Validator\ValidatorInterface;

/**
* "Mailto" URI handler
Expand All @@ -20,8 +20,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Mailto extends Uri
{
Expand Down
99 changes: 51 additions & 48 deletions src/Uri.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Uri
{
Expand Down Expand Up @@ -257,13 +255,13 @@ public function parse($uri)
$this->setUserInfo($userInfo);
}

$colonPos = strrpos($authority, ':');
if ($colonPos !== false) {
$port = substr($authority, $colonPos + 1);
if ($port) {
$this->setPort((int) $port);
}
$authority = substr($authority, 0, $colonPos);
$nMatches = preg_match('/:[\d]{1,5}$/', $authority, $matches);
if ($nMatches === 1) {
$portLength = strlen($matches[0]);
$port = substr($matches[0], 1);

$this->setPort((int) $port);
$authority = substr($authority, 0, -$portLength);
}

$this->setHost($authority);
Expand Down Expand Up @@ -407,7 +405,7 @@ public function normalize()
* (@link http://tools.ietf.org/html/rfc3986#section-5.2)
*
* @param Uri|string $baseUri
* @throws Exception\InvalidUriTypeException
* @throws Exception\InvalidArgumentException
* @return Uri
*/
public function resolve($baseUri)
Expand All @@ -419,13 +417,10 @@ public function resolve($baseUri)

if (is_string($baseUri)) {
$baseUri = new static($baseUri);
}

if (!$baseUri instanceof static) {
throw new Exception\InvalidUriTypeException(sprintf(
'Provided base URL is not an instance of "%s"',
get_called_class()
));
} elseif (!$baseUri instanceof Uri) {
throw new Exception\InvalidArgumentException(
'Provided base URI must be a string or a Uri object'
);
}

// Merging starts here...
Expand Down Expand Up @@ -665,6 +660,8 @@ public function setScheme($scheme)
*
* @param string $userInfo
* @return Uri
* @throws Exception\InvalidUriPartException If the schema definition
* does not have this part
*/
public function setUserInfo($userInfo)
{
Expand All @@ -676,7 +673,7 @@ public function setUserInfo($userInfo)
* Set the URI host
*
* Note that the generic syntax for URIs allows using host names which
* are not neceserily IPv4 addresses or valid DNS host names. For example,
* are not necessarily IPv4 addresses or valid DNS host names. For example,
* IPv6 addresses are allowed as well, and also an abstract "registered name"
* which may be any name composed of a valid set of characters, including,
* for example, tilda (~) and underscore (_) which are not allowed in DNS
Expand Down Expand Up @@ -758,6 +755,8 @@ public function setQuery($query)
*
* @param string $fragment
* @return Uri
* @throws Exception\InvalidUriPartException If the schema definition
* does not have this part
*/
public function setFragment($fragment)
{
Expand Down Expand Up @@ -835,20 +834,25 @@ public static function validateUserInfo($userInfo)
*/
public static function validateHost($host, $allowed = self::HOST_ALL)
{
if ($allowed & self::HOST_REGNAME) {
if (static::isValidRegName($host)) {
/*
* "first-match-wins" algorithm (RFC 3986):
* If host matches the rule for IPv4address, then it should be
* considered an IPv4 address literal and not a reg-name
*/
if ($allowed & self::HOST_IPVANY) {
if (static::isValidIpAddress($host, $allowed)) {
return true;
}
}

if ($allowed & self::HOST_DNS) {
if (static::isValidDnsHostname($host)) {
if ($allowed & self::HOST_REGNAME) {
if (static::isValidRegName($host)) {
return true;
}
}

if ($allowed & self::HOST_IPVANY) {
if (static::isValidIpAddress($host, $allowed)) {
if ($allowed & self::HOST_DNS) {
if (static::isValidDnsHostname($host)) {
return true;
}
}
Expand Down Expand Up @@ -997,7 +1001,7 @@ public static function encodeQueryFragment($input)
* method if one wants to test a URI string for it's scheme before doing
* anything with it.
*
* Will return the scmeme if found, or NULL if no scheme found (URI may
* Will return the scheme if found, or NULL if no scheme found (URI may
* still be valid, but not full)
*
* @param string $uriString
Expand Down Expand Up @@ -1107,30 +1111,29 @@ public static function merge($baseUri, $relativeUri)
protected static function isValidIpAddress($host, $allowed)
{
$validatorParams = array(
'allowipv4' => (bool) ($allowed & self::HOST_IPV4),
'allowipv6' => (bool) ($allowed & self::HOST_IPV6),
'allowipv4' => (bool) ($allowed & self::HOST_IPV4),
'allowipv6' => false,
'allowipvfuture' => false,
'allowliteral' => false,
);

if ($allowed & (self::HOST_IPV6 | self::HOST_IPVFUTURE)) {
if (preg_match('/^\[(.+)\]$/', $host, $match)) {
$host = $match[1];
$validatorParams['allowipv4'] = false;
}
}

if ($allowed & (self::HOST_IPV4 | self::HOST_IPV6)) {
$validator = new Validator\Ip($validatorParams);
if ($validator->isValid($host)) {
return true;
}
}

if ($allowed & self::HOST_IPVFUTURE) {
$regex = '/^v\.[[:xdigit:]]+[' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . ':]+$/';
return (bool) preg_match($regex, $host);
// Test only IPv4
$validator = new Validator\Ip($validatorParams);
$return = $validator->isValid($host);
if ($return) {
return true;
}

return false;
// IPv6 & IPvLiteral must be in literal format
$validatorParams = array(
'allowipv4' => false,
'allowipv6' => (bool) ($allowed & self::HOST_IPV6),
'allowipvfuture' => (bool) ($allowed & self::HOST_IPVFUTURE),
'allowliteral' => true,
);
static $regex = '/^\[.*\]$/';
$validator->setOptions($validatorParams);
return (preg_match($regex, $host) && $validator->isValid($host));
}

/**
Expand All @@ -1149,7 +1152,7 @@ protected static function isValidDnsHostname($host)
}

/**
* Check if an address is a valid registerd name (as defined by RFC-3986) address
* Check if an address is a valid registered name (as defined by RFC-3986) address
*
* @param string $host
* @return boolean
Expand All @@ -1171,7 +1174,7 @@ protected static function isValidRegName($host)
/**
* Normalize the scheme
*
* Usually this means simpy converting the scheme to lower case
* Usually this means simply converting the scheme to lower case
*
* @param string $scheme
* @return string
Expand Down Expand Up @@ -1261,7 +1264,7 @@ protected static function normalizeQuery($query)
/**
* Normalize the fragment part
*
* Currently this is exactly the same as _normalizeQuery().
* Currently this is exactly the same as normalizeQuery().
*
* @param string $fragment
* @return string
Expand Down
8 changes: 3 additions & 5 deletions src/UriFactory.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class UriFactory
{
Expand All @@ -34,7 +32,7 @@ abstract class UriFactory
*
* @var array
*/
static protected $schemeClasses = array(
protected static $schemeClasses = array(
'http' => 'Zend\Uri\Http',
'https' => 'Zend\Uri\Http',
'mailto' => 'Zend\Uri\Mailto',
Expand All @@ -47,7 +45,7 @@ abstract class UriFactory
* @param string $scheme
* @param string $class
*/
static public function registerScheme($scheme, $class)
public static function registerScheme($scheme, $class)
{
$scheme = strtolower($scheme);
static::$schemeClasses[$scheme] = $class;
Expand All @@ -61,7 +59,7 @@ static public function registerScheme($scheme, $class)
* @throws Exception\InvalidArgumentException
* @return \Zend\Uri\Uri
*/
static public function factory($uriString, $defaultScheme = null)
public static function factory($uriString, $defaultScheme = null)
{
if (!is_string($uriString)) {
throw new Exception\InvalidArgumentException(sprintf(
Expand Down
Loading

0 comments on commit 63e27fc

Please sign in to comment.