scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 125  →  ?path2? @ 126
/vendor/aura/uri/src/Aura/Uri/Host.php
@@ -0,0 +1,170 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri;
 
/**
*
* Processing the host
*
* @package Aura.Uri
*
*/
class Host
{
/**
*
* The public suffix list.
*
* @var array
*
*/
protected $psl;
 
/**
*
* The full Host this object represents.
*
* @var string
*
*/
protected $host;
 
/**
*
* Subdomain portion of host.
*
* @var string
*
*/
protected $subdomain;
 
/**
*
* Registerable domain portion of host.
*
* @var string
*
*/
protected $registerable_domain;
 
/**
*
* Public suffix portion of host.
*
* @var string
*
*/
protected $public_suffix;
 
/**
*
* Constructor.
*
* @param PublicSuffixList $psl Public suffix list.
*
* @param array $spec Host elements.
*
*/
public function __construct(PublicSuffixList $psl, array $spec = [])
{
$this->psl = $psl;
foreach ($spec as $key => $val) {
$this->$key = $val;
}
}
 
/**
*
* Returns this Host object as a string.
*
* @return string The full Host this object represents.
*
*/
public function __toString()
{
return $this->get();
}
 
/**
*
* Returns this Host object as a string.
*
* @return string The full Host this object represents.
*
*/
public function get()
{
if ($this->host !== null) {
return $this->host;
}
 
// retain only the elements that are not empty
$str = array_filter(
[$this->subdomain, $this->registerable_domain],
'strlen'
);
 
return implode('.', $str);
}
 
/**
*
* Sets values from a host string; overwrites any previous values.
*
* @param string $spec The host string to use; e.g., 'example.com'.
*
* @return void
*
*/
public function setFromString($spec)
{
$this->host = $spec;
$this->public_suffix = $this->psl->getPublicSuffix($spec);
$this->registerable_domain = $this->psl->getRegisterableDomain($spec);
$this->subdomain = $this->psl->getSubdomain($spec);
}
 
/**
*
* Returns the public suffix portion of the host.
*
* @return string
*
*/
public function getPublicSuffix()
{
return $this->public_suffix;
}
 
/**
*
* Returns the subdomain portion of the host.
*
* @return string
*
*/
public function getSubdomain()
{
return $this->subdomain;
}
 
/**
*
* Returns the registerable domain portion of the host.
*
* @return string
*
*/
public function getRegisterableDomain()
{
return $this->registerable_domain;
}
}
/vendor/aura/uri/src/Aura/Uri/Path.php
@@ -0,0 +1,118 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri;
 
/**
*
* Manage the Path
*
* @package Aura.Uri
*
*/
class Path extends \ArrayObject
{
/**
*
* The dot-format extension of the last path element, including the dot
* (for example, the ".rss" in "feed.rss").
*
* @var string
*
*/
protected $format;
 
/**
*
* Returns the path array as a string, including the format.
*
* @return string The path string.
*
*/
public function __toString()
{
$spec = $this->getArrayCopy();
$path = [];
// encode each path element
foreach ($spec as $elem) {
$path[] = rawurlencode($elem);
}
 
// create a string from the encoded elements
$url = implode('/', $path) . $this->format;
 
return !empty( $url ) ? '/' . $url : $url;
}
 
/**
*
* Sets the $path array and $format value from a string.
*
* This will overwrite any previous values.
*
* @param string $path The path string to use; for example,
* "/foo/bar/baz/dib.gir". A leading slash will *not* create an empty
* first element; if the string has a leading slash, it is ignored.
*
* @return void
*
*/
public function setFromString($path)
{
$this->exchangeArray([]);
$path = explode('/', $path);
 
if ($path[0] == '') {
array_shift($path);
}
 
foreach ($path as $key => $val) {
$this[$key] = urldecode($val);
}
 
// $key and $val are already at the end
$this->setFormat(null);
if ( isset($val) ) {
// find the last dot in the value
$pos = strrpos($val, '.');
if ($pos !== false) {
// remove from the path and retain as the format
$this[$key] = substr($val, 0, $pos);
$this->setFormat(substr($val, $pos));
}
}
}
 
/**
*
* Set the dot-format; remember to include the leading dot.
*
* @param string $format
*
* @return void
*
*/
public function setFormat($format)
{
$this->format = $format;
}
 
/**
*
* Get the dot-format extension.
*
* @return string
*/
public function getFormat()
{
return $this->format;
}
}
/vendor/aura/uri/src/Aura/Uri/PublicSuffixList.php
@@ -0,0 +1,146 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri;
 
/**
*
* Object representation of the Public Suffix List
*
* @package Aura.Uri
*
*/
class PublicSuffixList
{
/**
*
* Public suffix list data.
*
* @var array
*
*/
protected $psl;
 
/**
*
* Constructor.
*
* @param array $list Array representation of the Public Suffix List
*
*/
public function __construct(array $list)
{
$this->psl = $list;
}
 
/**
* Returns the public suffix portion of provided host
*
* @param string $host host
* @return string public suffix
*/
public function getPublicSuffix($host)
{
if (strpos($host, '.') === 0) {
return null;
}
 
if (strpos($host, '.') === false) {
return null;
}
 
$host = strtolower($host);
$parts = array_reverse(explode('.', $host));
$publicSuffix = array();
$psl = $this->psl;
 
foreach ($parts as $part) {
if (array_key_exists($part, $psl)
&& array_key_exists('!', $psl[$part])) {
break;
}
 
if (array_key_exists($part, $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl[$part];
continue;
}
 
if (array_key_exists('*', $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl['*'];
continue;
}
 
// Avoids improper parsing when $host's subdomain + public suffix ===
// a valid public suffix (e.g. host 'us.example.com' and public suffix 'us.com')
break;
}
 
// Apply algorithm rule #2: If no rules match, the prevailing rule is "*".
if (empty($publicSuffix)) {
$publicSuffix[0] = $parts[0];
}
 
return implode('.', array_filter($publicSuffix, 'strlen'));
}
 
/**
* Returns registerable domain portion of provided host
*
* Per the test cases provided by Mozilla
* (http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
* this method should return null if the domain provided is a public suffix.
*
* @param string $host host
* @return string registerable domain
*/
public function getRegisterableDomain($host)
{
if (strpos($host, '.') === false) {
return null;
}
 
$host = strtolower($host);
$publicSuffix = $this->getPublicSuffix($host);
 
if ($publicSuffix === null || $host == $publicSuffix) {
return null;
}
 
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
$hostParts = array_reverse(explode('.', $host));
$registerableDomainParts = array_slice($hostParts, 0, count($publicSuffixParts) + 1);
 
return implode('.', array_reverse($registerableDomainParts));
}
 
/**
* Returns the subdomain portion of provided host
*
* @param string $host host
* @return string subdomain
*/
public function getSubdomain($host)
{
$host = strtolower($host);
$registerableDomain = $this->getRegisterableDomain($host);
 
if ($registerableDomain === null || $host == $registerableDomain) {
return null;
}
 
$registerableDomainParts = array_reverse(explode('.', $registerableDomain));
$hostParts = array_reverse(explode('.', $host));
$subdomainParts = array_slice($hostParts, count($registerableDomainParts));
 
return implode('.', array_reverse($subdomainParts));
}
}
/vendor/aura/uri/src/Aura/Uri/Query.php
@@ -0,0 +1,83 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri;
 
/**
*
* Processing the query string
*
* @package Aura.Uri
*
*/
class Query extends \ArrayObject
{
/**
*
* Returns the query portion as a string.
*
* @return string The query string; e.g., `foo=bar&baz=dib`.
*
*/
public function __toString()
{
return $this->buildString($this->getArrayCopy());
}
 
/**
*
* Sets values from a query string; overwrites any previous values.
*
* To set from an array, use `exchangeArray()`.
*
* @param string $spec The query string to use; for example,
* `foo=bar&baz=dib`.
*
* @return void
*
*/
public function setFromString($spec)
{
parse_str($spec, $query);
$this->exchangeArray($query);
}
 
/**
*
* Build string from an array
*
* @param array $array
*
* @param string $prefix Defaults to null
*
* @return string Returns a string
*/
protected function buildString(array $array, $prefix = null)
{
$elem = [];
foreach ($array as $key => $val) {
 
$key = ($prefix)
? $prefix . '[' . $key . ']'
: $key;
 
if (is_array($val)) {
$elem[] = $this->buildString($val, $key);
} else {
$val = ($val === null || $val === false)
? ''
: rawurlencode($val);
$elem[] = rawurlencode($key) . '=' . $val;
}
}
 
return implode('&', $elem);
}
}
/vendor/aura/uri/src/Aura/Uri/Url/Factory.php
@@ -0,0 +1,160 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri\Url;
 
use Aura\Uri\Url;
use Aura\Uri\Path;
use Aura\Uri\Query;
use Aura\Uri\Host;
use Aura\Uri\PublicSuffixList;
 
/**
*
* Factory to create new Url objects.
*
* @package Aura.Uri
*
*/
class Factory
{
/**
*
* A string representing the current URL, built from $_SERVER.
*
* @var string
*
*/
protected $current;
 
/**
* Public suffix list
*
* @var PublicSuffixList
*/
protected $psl;
 
/**
*
* Constructor.
*
* @param array $server An array copy of $_SERVER.
*
* @param PublicSuffixList $psl Public suffix list
*/
public function __construct(array $server, PublicSuffixList $psl)
{
$https = isset($server['HTTPS'])
&& strtolower($server['HTTPS']) == 'on';
 
$ssl = isset($server['SERVER_PORT'])
&& $server['SERVER_PORT'] == 443;
 
if ($https || $ssl) {
$scheme = 'https';
} else {
$scheme = 'http';
}
 
if (isset($server['HTTP_HOST'])) {
$host = $server['HTTP_HOST'];
} else {
$host = '';
}
 
if (isset($server['REQUEST_URI'])) {
$resource = $server['REQUEST_URI'];
} else {
$resource = '';
}
 
$this->current = $scheme . '://' . $host . $resource;
 
$this->psl = $psl;
}
 
/**
*
* Creates and returns a new Url object.
*
* If no host is specified, the parsing will fail.
*
* @param string $spec The URL string to set from.
*
* @return Url
*
*/
public function newInstance($spec)
{
$elem = [
'scheme' => null,
'user' => null,
'pass' => null,
'host' => null,
'port' => null,
'path' => null,
'query' => null,
'fragment' => null,
];
 
$parts = $this->parse($spec);
 
$elem = (array) $parts + $elem;
 
$path = new Path([]);
$path->setFromString($elem['path']);
 
$query = new Query([]);
$query->setFromString($elem['query']);
 
$host = new Host($this->psl, []);
$host->setFromString($elem['host']);
 
return new Url(
$elem['scheme'],
$elem['user'],
$elem['pass'],
$host,
$elem['port'],
$path,
$query,
$elem['fragment']
);
}
 
/**
*
* Creates and returns a new URL object based on the current URL.
*
* @return Url
*
*/
public function newCurrent()
{
return $this->newInstance($this->current);
}
 
/**
* Parses url
*
* @param string $spec Url to parse
* @return array Parsed url
*/
public function parse($spec)
{
preg_match(Url::SCHEME_PATTERN, $spec, $schemeMatches);
 
if (empty($schemeMatches)) {
$spec = 'http://' . preg_replace('#^//#', '', $spec, 1);
}
 
return parse_url($spec);
}
}
/vendor/aura/uri/src/Aura/Uri/Url.php
@@ -0,0 +1,358 @@
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @package Aura.Uri
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Uri;
 
/**
*
* Manipulates and generates URLs.
*
* @package Aura.Uri
*
*/
class Url
{
/**
* Pattern for URL scheme matching
*/
const SCHEME_PATTERN = '#^(http|ftp)s?://#i';
 
/**
*
* The scheme (for example 'http' or 'https').
*
* @var string
*
*/
protected $scheme;
 
/**
*
* The username, if any.
*
* @var string
*
*/
protected $user;
 
/**
*
* The password, if any.
*
* @var string
*
*/
protected $pass;
 
/**
*
* The Host object
*
* @var Host
*
*/
protected $host;
 
/**
*
* The port number (for example, '80').
*
* @var string
*
*/
protected $port;
 
/**
*
* A Path object.
*
* @var Path
*
*/
protected $path;
 
/**
*
* A Query object.
*
* @var Query
*
*/
protected $query;
 
/**
*
* The fragment portion (for example, the "foo" in "#foo").
*
* @var string
*
*/
protected $fragment;
 
// authority = userinfo@host:port
 
/**
*
* Constructor.
*
* @param string $scheme The URL scheme (e.g. `http`).
*
* @param string $user The username.
*
* @param string $pass The password.
*
* @param Host $host The host elements.
*
* @param int $port The port number.
*
* @param Path $path The path elements, including format.
*
* @param Query $query The query elements.
*
* @param string $fragment The fragment.
*
*/
public function __construct(
$scheme,
$user,
$pass,
Host $host,
$port,
Path $path,
Query $query,
$fragment
) {
$this->scheme = $scheme;
$this->user = $user;
$this->pass = $pass;
$this->host = $host;
$this->port = $port;
$this->path = $path;
$this->query = $query;
$this->fragment = $fragment;
}
 
/**
*
* Converts the URI object to a string and returns it.
*
* @return string The full URI this object represents.
*
*/
public function __toString()
{
return $this->getFull(true);
}
 
/**
*
* Magic get for properties.
*
* @param string $key The property to get.
*
* @return mixed The value of the property.
*
*/
public function __get($key)
{
return $this->$key;
}
 
/**
*
* Returns the URL as a string, not including scheme or host.
*
* @return string The URL string.
*
*/
public function get()
{
// get the query as a string
$query = $this->query->__toString();
 
// we use trim() instead of empty() on string
// elements to allow for string-zero values.
return $this->path->__toString()
. (empty($query) ? '' : '?' . $query)
. (trim($this->fragment) === '' ? '' : '#' . rawurlencode($this->fragment));
}
 
/**
*
* Returns the URL as a string, including the scheme and host.
*
* @return string The URL string.
*
*/
public function getFull()
{
// start with the scheme
$url = empty($this->scheme)
? ''
: rawurlencode($this->scheme) . '://';
 
// add the username and password, if any.
if (! empty($this->user)) {
$url .= rawurlencode($this->user);
if (! empty($this->pass)) {
$url .= ':' . rawurlencode($this->pass);
}
$url .= '@';
}
 
$host = $this->host->__toString();
 
// add the host and port, if any.
$url .= (empty($this->host) ? '' : rawurlencode($this->host))
. (empty($this->port) ? '' : ':' . (int) $this->port);
 
return $url . $this->get();
}
 
/**
*
* Returns the URL as a string, including the host but excluding the scheme
*
* @return string The URL string.
*
*/
public function getSchemeless()
{
return preg_replace(self::SCHEME_PATTERN, '//', $this->getFull(), 1);
}
 
/**
*
* Set the scheme (for example 'http' or 'https').
*
* @param string $scheme The scheme (for example 'http' or 'https').
*
* @return $this
*
*/
public function setScheme($scheme)
{
$this->scheme = $scheme;
 
return $this;
}
 
/**
*
* Sets the username.
*
* @param string $user The username.
*
* @return $this
*
*/
public function setUser($user)
{
$this->user = $user;
 
return $this;
}
 
/**
*
* Sets the password.
*
* @param string $pass The password.
*
* @return $this
*
*/
public function setPass($pass)
{
$this->pass = $pass;
 
return $this;
}
 
/**
*
* Sets the Host object for this URL.
*
* @param Host $host The host name.
*
* @return $this
*
*/
public function setHost(Host $host)
{
$this->host = $host;
 
return $this;
}
 
/**
*
* Sets the port number (for example, '80').
*
* @param int $port The port number.
*
* @return $this
*
*/
public function setPort($port)
{
$this->port = $port;
 
return $this;
}
 
/**
*
* Sets the Path object for this URL.
*
* @param Path $path The Path object.
*
* @return $this
*
*/
public function setPath(Path $path)
{
$this->path = $path;
 
return $this;
}
 
/**
*
* Sets the Query object for this URL.
*
* @param Query $query The Query object.
*
* @return $this
*
*/
public function setQuery(Query $query)
{
$this->query = $query;
 
return $this;
}
 
/**
*
* Sets the fragment portion (for example, the "foo" in "#foo").
*
* @param string $fragment The fragment.
*
* @return $this
*
*/
public function setFragment($fragment)
{
$this->fragment = $fragment;
 
return $this;
}
}