cvs: pear /Net_URL URL.php package.xml /Net_URL/docs example.php

From: Date: Sat, 26 Jun 2004 12:45:07 +0000
Subject: cvs: pear /Net_URL URL.php package.xml /Net_URL/docs example.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21155@lists.php.net to get a copy of this message
richard Sat Jun 26 08:45:07 2004 EDT Modified files: /pear/Net_URL URL.php package.xml /pear/Net_URL/docs example.php Log: Upgrade Net_URL to PHP5 & E_STRICT

http://cvs.php.net/diff.php/pear/Net_URL/URL.php?r1=1.36&r2=1.37&ty=u Index: pear/Net_URL/URL.php diff -u pear/Net_URL/URL.php:1.36 pear/Net_URL/URL.php:1.37 --- pear/Net_URL/URL.php:1.36 Sat Jun 19 14:58:50 2004 +++ pear/Net_URL/URL.php Sat Jun 26 08:45:07 2004 @@ -32,9 +32,10 @@ // | Author: Richard Heyes <richard at php net> | // +-----------------------------------------------------------------------+ // -// $Id: URL.php,v 1.36 2004/06/19 18:58:50 richard Exp $ +// $Id: URL.php,v 1.37 2004/06/26 12:45:07 richard Exp $ // -// Net_URL Class +// Net_URL Class (PHP5 Only) + class Net_URL { @@ -42,74 +43,64 @@ * Full url * @var string */ - var $url; + public $url; /** * Protocol * @var string */ - var $protocol; + public $protocol; /** * Username * @var string */ - var $username; + public $user; /** * Password * @var string */ - var $password; + public $pass; /** * Host * @var string */ - var $host; + public $host; /** * Port * @var integer */ - var $port; + public $port; /** * Path * @var string */ - var $path; + public $path; /** * Query string * @var array */ - var $querystring; + public $querystring; /** * Anchor * @var string */ - var $anchor; + public $anchor; /** - * Whether to use [] - * @var bool + * Whether to use [] in querystrings + * @var boolean */ - var $useBrackets; + public $useBrackets; /** - * PHP4 Constructor - * - * @see __construct() - */ - function Net_URL($url = null, $useBrackets = true) - { - $this->__construct($url, $useBrackets); - } - - /** - * PHP5 Constructor + * Constructor * * Parses the given url and stores the various parts * Defaults are used in certain cases @@ -119,10 +110,8 @@ * multiple querystrings with the same name * exist */ - function __construct($url = null, $useBrackets = true) + public function __construct($url = null, $useBrackets = true) { - $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; - $this->useBrackets = $useBrackets; $this->url = $url; $this->user = ''; @@ -136,12 +125,12 @@ // Only use defaults if not an absolute URL given if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { - $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); + $this->protocol = (@$_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); /** * Figure out host/port */ - if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { + if (!empty($_SERVER['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $_SERVER['HTTP_HOST'], $matches)) { $host = $matches[1]; if (!empty($matches[3])) { $port = $matches[3]; @@ -152,10 +141,10 @@ $this->user = ''; $this->pass = ''; - $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); - $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); - $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; - $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; + $this->host = !empty($host) ? $host : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'); + $this->port = !empty($port) ? $port : (isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : $this->getStandardPort($this->protocol)); + $this->path = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '/'; + $this->querystring = isset($_SERVER['QUERY_STRING']) ? $this->_parseRawQuerystring($_SERVER['QUERY_STRING']) : null; $this->anchor = ''; } @@ -205,9 +194,8 @@ * Returns full url * * @return string Full url - * @access public */ - function getURL() + public function getURL() { $querystring = $this->getQueryString(); @@ -228,9 +216,8 @@ * @param string $name Name of item * @param string $value Value of item * @param bool $preencoded Whether value is urlencoded or not, default = not - * @access public */ - function addQueryString($name, $value, $preencoded = false) + public function addQueryString($name, $value, $preencoded = false) { if ($preencoded) { $this->querystring[$name] = $value; @@ -243,9 +230,8 @@ * Removes a querystring item * * @param string $name Name of item - * @access public */ - function removeQueryString($name) + public function removeQueryString($name) { if (isset($this->querystring[$name])) { unset($this->querystring[$name]); @@ -256,9 +242,8 @@ * Sets the querystring to literally what you supply * * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc - * @access public */ - function addRawQueryString($querystring) + public function addRawQueryString($querystring) { $this->querystring = $this->_parseRawQueryString($querystring); } @@ -267,9 +252,8 @@ * Returns flat querystring * * @return string Querystring - * @access public */ - function getQueryString() + public function getQueryString() { if (!empty($this->querystring)) { foreach ($this->querystring as $name => $value) { @@ -292,42 +276,15 @@ } /** - * Parses raw querystring and returns an array of it + * Forces the URL to a particular protocol * - * @param string $querystring The querystring to parse - * @return array An array of the querystring data - * @access private + * @param string $protocol Protocol to force the URL to + * @param integer $port Optional port (standard port is used by default) */ - function _parseRawQuerystring($querystring) + public function setProtocol($protocol, $port = null) { - $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); - $return = array(); - - foreach ($parts as $part) { - if (strpos($part, '=') !== false) { - $value = substr($part, strpos($part, '=') + 1); - $key = substr($part, 0, strpos($part, '=')); - } else { - $value = null; - $key = $part; - } - if (substr($key, -2) == '[]') { - $key = substr($key, 0, -2); - if (@!is_array($return[$key])) { - $return[$key] = array(); - $return[$key][] = $value; - } else { - $return[$key][] = $value; - } - } elseif (!$this->useBrackets AND !empty($return[$key])) { - $return[$key] = (array)$return[$key]; - $return[$key][] = $value; - } else { - $return[$key] = $value; - } - } - - return $return; + $this->protocol = $protocol; + $this->port = is_null($port) ? $this->getStandardPort() : $port; } /** @@ -338,12 +295,10 @@ * /foo/bar/../../boo.php => /boo.php * /foo/bar/.././/boo.php => /foo/boo.php * - * This method can also be called statically. - * * @param string $url URL path to resolve * @return string The result */ - function resolvePath($path) + public static function resolvePath($path) { $path = explode('/', str_replace('//', '/', $path)); @@ -380,7 +335,7 @@ * * @author Philippe Jausions <Philippe.Jausions@11abacus.com> */ - function getStandardPort($scheme) + public static function getStandardPort($scheme) { switch (strtolower($scheme)) { case 'http': return 80; @@ -395,15 +350,41 @@ } /** - * Forces the URL to a particular protocol + * Parses raw querystring and returns an array of it * - * @param string $protocol Protocol to force the URL to - * @param integer $port Optional port (standard port is used by default) + * @param string $querystring The querystring to parse + * @return array An array of the querystring data */ - function setProtocol($protocol, $port = null) + private function _parseRawQuerystring($querystring) { - $this->protocol = $protocol; - $this->port = is_null($port) ? $this->getStandardPort() : $port; + $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); + $return = array(); + + foreach ($parts as $part) { + if (strpos($part, '=') !== false) { + $value = substr($part, strpos($part, '=') + 1); + $key = substr($part, 0, strpos($part, '=')); + } else { + $value = null; + $key = $part; + } + if (substr($key, -2) == '[]') { + $key = substr($key, 0, -2); + if (@!is_array($return[$key])) { + $return[$key] = array(); + $return[$key][] = $value; + } else { + $return[$key][] = $value; + } + } elseif (!$this->useBrackets AND !empty($return[$key])) { + $return[$key] = (array)$return[$key]; + $return[$key][] = $value; + } else { + $return[$key] = $value; + } + } + + return $return; } } http://cvs.php.net/diff.php/pear/Net_URL/package.xml?r1=1.10&r2=1.11&ty=u Index: pear/Net_URL/package.xml diff -u pear/Net_URL/package.xml:1.10 pear/Net_URL/package.xml:1.11 --- pear/Net_URL/package.xml:1.10 Sat May 8 13:48:07 2004 +++ pear/Net_URL/package.xml Sat Jun 26 08:45:07 2004 @@ -14,11 +14,11 @@ </maintainers> <release> - <version>1.0.12</version> - <date>2004-05-08</date> + <version>2.0.0</version> + <date>2004-06-26</date> <license>BSD</license> <state>stable</state> - <notes>Bug fixes release (#704 and #1036)</notes> + <notes>Convert to PHP5 only. PHP4 users should continue with version 1.0.14</notes> <filelist> <file role="php" baseinstalldir="Net" name="URL.php"/> @@ -27,7 +27,31 @@ </release> - <changelog> + <changelog> + <release> + <version>1.0.14</version> + <date>2004-06-19</date> + <license>BSD</license> + <state>stable</state> + <notes>Whitespace</notes> + </release> + + <release> + <version>1.0.13</version> + <date>2004-06-05</date> + <license>BSD</license> + <state>stable</state> + <notes>Fix bug 1558</notes> + </release> + + <release> + <version>1.0.12</version> + <date>2004-05-08</date> + <license>BSD</license> + <state>stable</state> + <notes>Bug fixes release (#704 and #1036)</notes> + </release> + <release> <version>1.0.11</version> <date>2004-01-17</date> http://cvs.php.net/diff.php/pear/Net_URL/docs/example.php?r1=1.9&r2=1.10&ty=u Index: pear/Net_URL/docs/example.php diff -u pear/Net_URL/docs/example.php:1.9 pear/Net_URL/docs/example.php:1.10 --- pear/Net_URL/docs/example.php:1.9 Sat May 8 13:48:08 2004 +++ pear/Net_URL/docs/example.php Sat Jun 26 08:45:07 2004 @@ -31,14 +31,15 @@ // +-----------------------------------------------------------------------+ // | Author: Richard Heyes <richard at php net> | // +-----------------------------------------------------------------------+ -// $Id: example.php,v 1.9 2004/05/08 17:48:08 richard Exp $ +// $Id: example.php,v 1.10 2004/06/26 12:45:07 richard Exp $ /** * This example will decode the url given and display its * constituent parts. */ + error_reporting(E_ALL | E_STRICT); -// include('../URL.php'); - include('Net/URL.php'); + //include('../URL.php'); + include('Net/URL.php'); //$url = &new Net_URL('https://www.example.com/foo/bar/index.php?foo=bar'); $url = new Net_URL('https://example.com/pls/portal30/PORTAL30.wwpob_page.changetabs?p_back_url=http%3A%2F%2Fexample.com%2Fservlet%2Fpage%3F_pageid%3D360%2C366%2C368%2C382%26_dad%3Dportal30%26_schema%3DPORTAL30&foo=bar'); @@ -64,8 +65,11 @@ Anchor.....: <?=$url->anchor?> -Full URL...: <?=$url->getUrl()?> -</pre> +Full URL...: <?=$url->getUrl()?> + + +Resolve path (/.././/foo/bar/joe/./././../jabba): <b><?=Net_URL::resolvePath('/.././/foo/bar/joe/./././../jabba')?></b> +</pre> </body> </html>
« previous php.pear.cvs (#21155) next »