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

From: Date: Sat, 29 Oct 2005 11:17:56 +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-35946@lists.php.net to get a copy of this message
dufuz Sat Oct 29 07:17:56 2005 EDT Modified files: /pear/Net_URL URL.php package.xml /pear/Net_URL/docs example.php Log: Revert back to the PHP 4 version (But it still includes all the bug fixes that came after the PHP 5 commit)

http://cvs.php.net/diff.php/pear/Net_URL/URL.php?r1=1.41&r2=1.42&ty=u Index: pear/Net_URL/URL.php diff -u pear/Net_URL/URL.php:1.41 pear/Net_URL/URL.php:1.42 --- pear/Net_URL/URL.php:1.41 Tue Mar 1 22:42:22 2005 +++ pear/Net_URL/URL.php Sat Oct 29 07:17:56 2005 @@ -32,10 +32,9 @@ // | Author: Richard Heyes <richard at php net> | // +-----------------------------------------------------------------------+ // -// $Id: URL.php,v 1.41 2005/03/02 03:42:22 richard Exp $ +// $Id: URL.php,v 1.42 2005/10/29 11:17:56 dufuz Exp $ // -// Net_URL Class (PHP5 Only) - +// Net_URL Class class Net_URL { @@ -43,64 +42,74 @@ * Full url * @var string */ - public $url; + var $url; /** * Protocol * @var string */ - public $protocol; + var $protocol; /** * Username * @var string */ - public $user; + var $username; /** * Password * @var string */ - public $pass; + var $password; /** * Host * @var string */ - public $host; + var $host; /** * Port * @var integer */ - public $port; + var $port; /** * Path * @var string */ - public $path; + var $path; /** * Query string * @var array */ - public $querystring; + var $querystring; /** * Anchor * @var string */ - public $anchor; + var $anchor; /** - * Whether to use [] in querystrings - * @var boolean + * Whether to use [] + * @var bool */ - public $useBrackets; + var $useBrackets; + + /** + * PHP4 Constructor + * + * @see __construct() + */ + function Net_URL($url = null, $useBrackets = true) + { + $this->__construct($url, $useBrackets); + } /** - * Constructor + * PHP5 Constructor * * Parses the given url and stores the various parts * Defaults are used in certain cases @@ -110,8 +119,10 @@ * multiple querystrings with the same name * exist */ - public function __construct($url = null, $useBrackets = true) + function __construct($url = null, $useBrackets = true) { + $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; + $this->useBrackets = $useBrackets; $this->url = $url; $this->user = ''; @@ -124,13 +135,12 @@ // Only use defaults if not an absolute URL given if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { - $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); /** * Figure out host/port */ - if (!empty($_SERVER['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $_SERVER['HTTP_HOST'], $matches)) { + if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { $host = $matches[1]; if (!empty($matches[3])) { $port = $matches[3]; @@ -141,10 +151,10 @@ $this->user = ''; $this->pass = ''; - $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->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->anchor = ''; } @@ -194,8 +204,9 @@ * Returns full url * * @return string Full url + * @access public */ - public function getURL() + function getURL() { $querystring = $this->getQueryString(); @@ -216,8 +227,9 @@ * @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 */ - public function addQueryString($name, $value, $preencoded = false) + function addQueryString($name, $value, $preencoded = false) { if ($preencoded) { $this->querystring[$name] = $value; @@ -230,8 +242,9 @@ * Removes a querystring item * * @param string $name Name of item + * @access public */ - public function removeQueryString($name) + function removeQueryString($name) { if (isset($this->querystring[$name])) { unset($this->querystring[$name]); @@ -242,8 +255,9 @@ * 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 */ - public function addRawQueryString($querystring) + function addRawQueryString($querystring) { $this->querystring = $this->_parseRawQueryString($querystring); } @@ -252,15 +266,15 @@ * Returns flat querystring * * @return string Querystring + * @access public */ - public function getQueryString() + function getQueryString() { if (!empty($this->querystring)) { foreach ($this->querystring as $name => $value) { - // Encode var name $name = rawurlencode($name); - + if (is_array($value)) { foreach ($value as $k => $v) { $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); @@ -280,15 +294,52 @@ } /** - * 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 + * @access private */ - public function setProtocol($protocol, $port = null) + function _parseRawQuerystring($querystring) { - $this->protocol = $protocol; - $this->port = is_null($port) ? $this->getStandardPort($protocol) : $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; + } + + $key = rawurldecode($key); + + if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { + $key = $matches[1]; + $idx = $matches[2]; + + // Ensure is an array + if (empty($return[$key]) || !is_array($return[$key])) { + $return[$key] = array(); + } + + // Add data + if ($idx === '') { + $return[$key][] = $value; + } else { + $return[$key][$idx] = $value; + } + } elseif (!$this->useBrackets AND !empty($return[$key])) { + $return[$key] = (array)$return[$key]; + $return[$key][] = $value; + } else { + $return[$key] = $value; + } + } + + return $return; } /** @@ -299,10 +350,12 @@ * /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 */ - public static function resolvePath($path) + function resolvePath($path) { $path = explode('/', str_replace('//', '/', $path)); @@ -339,7 +392,7 @@ * * @author Philippe Jausions <Philippe.Jausions@11abacus.com> */ - public static function getStandardPort($scheme) + function getStandardPort($scheme) { switch (strtolower($scheme)) { case 'http': return 80; @@ -354,53 +407,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 + * @param string $protocol Protocol to force the URL to + * @param integer $port Optional port (standard port is used by default) */ - private function _parseRawQuerystring($querystring) + 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; - } - - $key = rawurldecode($key); - - if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { - $key = $matches[1]; - $idx = $matches[2]; - - // Ensure is an array - if (empty($return[$key]) || !is_array($return[$key])) { - $return[$key] = array(); - } - - // Add data - if ($idx === '') { - $return[$key][] = $value; - - } else { - $return[$key][$idx] = $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($protocal) : $port; } } http://cvs.php.net/diff.php/pear/Net_URL/package.xml?r1=1.13&r2=1.14&ty=u Index: pear/Net_URL/package.xml diff -u pear/Net_URL/package.xml:1.13 pear/Net_URL/package.xml:1.14 --- pear/Net_URL/package.xml:1.13 Sat Jun 26 13:46:05 2004 +++ pear/Net_URL/package.xml Sat Oct 29 07:17:56 2005 @@ -1,36 +1,149 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> - +<?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> - - <name>Net_URL</name> - <summary>Easy parsing of Urls</summary> - <description>Provides easy parsing of URLs and their constituent parts.</description> - - <maintainers> - <maintainer> - <user>richard</user> - <name>Richard heyes</name> - <email>richard@php.net</email> - <role>lead</role> - </maintainer> - </maintainers> - - <release> - <version>2.0.0</version> - <date>2004-06-26</date> + <name>Net_URL</name> + <summary>Easy parsing of Urls</summary> + <description>Provides easy parsing of URLs and their constituent parts.</description> + + <maintainers> + <maintainer> + <user>richard</user> + <name>Richard heyes</name> + <email>richard@php.net</email> + <role>lead</role> + </maintainer> + </maintainers> + + <release> + <version>1.0.15</version> + <date>2005-11-04</date> + <license>BSD</license> + <state>stable</state> + <notes> +- Fix bug #2334 square brackets in var names are not encoded +- Fix request #2824 error suppresion is used where code canbe easily changed to avoid errors +- Fix bug #3159Net_URL::setProtocol calls getStandardPort() incorrectly + </notes> + + <filelist> + <file role="php" baseinstalldir="Net" name="URL.php"/> + <file role="doc" baseinstalldir="Net" name="docs/example.php"/> + </filelist> + </release> + + + <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>Convert to PHP5 only. PHP4 users should continue with version 1.0.14</notes> - - <filelist> - <file role="php" baseinstalldir="Net" name="URL.php"/> - <file role="doc" baseinstalldir="Net" name="docs/example.php"/> - </filelist> - - <deps> - <dep type="php" rel="ge" version="5.0" /> - </deps> - - </release> + <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> + <license>BSD</license> + <state>stable</state> + <notes>Bug fixes release (#83 and #471)</notes> + </release> + + <release> + <version>1.0.10</version> + <date>2002-04-06</date> + <license>BSD</license> + <state>stable</state> + <notes>Be more flexible in what constitutes a scheme</notes> + </release> + + <release> + <version>1.0.9</version> + <date>2002-04-05</date> + <state>stable</state> + <notes>Fix couple of absolute URL bugs.</notes> + </release> + + <release> + <version>1.0.8</version> + <date>2002-03-06</date> + <state>stable</state> + <notes>Various bugs. Remove auto setting of default url to '/' if a url is supplied +to the constructor. May cause BC issues.</notes> + </release> + + <release> + <version>1.0.7</version> + <date>2002-12-07</date> + <state>stable</state> + <notes>Added method to resolve URL paths of //, ../ and ./</notes> + </release> + + <release> + <version>1.0.6</version> + <date>2002-12-07</date> + <state>stable</state> + <notes>Make usage of [] optional</notes> + </release> + + <release> + <version>1.0.5</version> + <date>2002-11-14</date> + <state>stable</state> + <notes>Allow for URLS such as ...?foo</notes> + </release> + + <release> + <version>1.0.4</version> + <date>2002-07-27</date> + <state>stable</state> + <notes>License change +</notes> + </release> + + <release> + <version>1.0.3</version> + <date>2002-06-20</date> + <state>stable</state> + <notes>Now uses HTTP_HOST if available.</notes> + </release> + + <release> + <version>1.0.2</version> + <date>2002-04-28</date> + <state>stable</state> + <notes>updated to fix a minor irritation when running on windows</notes> + </release> + + <release> + <version>1.0.1</version> + <date>2002-04-28</date> + <state>stable</state> + <notes>Maintenance release. Bugs fixed with path detection and defaults.</notes> + </release> + + <release> + <version>1.0</version> + <date>2002-02-17</date> + <state>stable</state> + <notes>This is the initial release of the Net_URL package.</notes> + </release> + + </changelog> </package> http://cvs.php.net/diff.php/pear/Net_URL/docs/example.php?r1=1.10&r2=1.11&ty=u Index: pear/Net_URL/docs/example.php diff -u pear/Net_URL/docs/example.php:1.10 pear/Net_URL/docs/example.php:1.11 --- pear/Net_URL/docs/example.php:1.10 Sat Jun 26 08:45:07 2004 +++ pear/Net_URL/docs/example.php Sat Oct 29 07:17:56 2005 @@ -31,15 +31,14 @@ // +-----------------------------------------------------------------------+ // | Author: Richard Heyes <richard at php net> | // +-----------------------------------------------------------------------+ -// $Id: example.php,v 1.10 2004/06/26 12:45:07 richard Exp $ +// $Id: example.php,v 1.11 2005/10/29 11:17:56 dufuz 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'); @@ -65,11 +64,8 @@ Anchor.....: <?=$url->anchor?> -Full URL...: <?=$url->getUrl()?> - - -Resolve path (/.././/foo/bar/joe/./././../jabba): <b><?=Net_URL::resolvePath('/.././/foo/bar/joe/./././../jabba')?></b> -</pre> +Full URL...: <?=$url->getUrl()?> +</pre> </body> </html>
« previous php.pear.cvs (#35946) next »