Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Regenerate package, non static API

  • Loading branch information...
commit e322524e3bfb2a028e47c5898e9bd1187c8991d4 1 parent dd9ea83
@CloCkWeRX CloCkWeRX authored
View
83 HTTP2.php
@@ -21,10 +21,12 @@
* @link http://pear.php.net/package/HTTP2
*/
+require_once 'HTTP2/Exception.php';
+
/**
* Miscellaneous HTTP Utilities
*
- * PEAR::HTTP2 provides static shorthand methods for generating HTTP dates,
+ * PEAR::HTTP2 provides shorthand methods for generating HTTP dates,
* issueing HTTP HEAD requests, building absolute URIs, firing redirects and
* negotiating user preferred language.
*
@@ -51,10 +53,8 @@ class HTTP2
* @param mixed $time unix timestamp or date (default = current time)
*
* @return mixed GMT date string, or false for an invalid $time parameter
- * @access public
- * @static
*/
- function Date($time = null)
+ public function Date($time = null)
{
if (!isset($time)) {
$time = time();
@@ -81,6 +81,7 @@ function Date($time = null)
*
* <code>
* require_once 'HTTP2.php';
+ * $http = new HTTP2();
* $langs = array(
* 'en' => 'locales/en',
* 'en-US' => 'locales/en',
@@ -89,7 +90,7 @@ function Date($time = null)
* 'de-DE' => 'locales/de',
* 'de-AT' => 'locales/de',
* );
- * $neg = HTTP2::negotiateLanguage($langs);
+ * $neg = $http->negotiateLanguage($langs);
* $dir = $langs[$neg];
* </code>
*
@@ -98,10 +99,8 @@ function Date($time = null)
* @param string $default The default language to use if none is found.
*
* @return string The negotiated language result or the supplied default.
- * @static
- * @access public
*/
- function negotiateLanguage($supported, $default = 'en-US')
+ public function negotiateLanguage($supported, $default = 'en-US')
{
$supp = array();
foreach ($supported as $lang => $isSupported) {
@@ -115,7 +114,7 @@ function negotiateLanguage($supported, $default = 'en-US')
}
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $match = HTTP2::_matchAccept($_SERVER['HTTP_ACCEPT_LANGUAGE'],
+ $match = $this->_matchAccept($_SERVER['HTTP_ACCEPT_LANGUAGE'],
$supp);
if (!is_null($match)) {
return $match;
@@ -141,23 +140,21 @@ function negotiateLanguage($supported, $default = 'en-US')
*
* <code>
* require_once 'HTTP2.php';
+ * $http = new HTTP2();
* $charsets = array(
* 'UTF-8',
* 'ISO-8859-1',
* );
- * $charset = HTTP2::negotiateCharset($charsets);
+ * $charset = $http->negotiateCharset($charsets);
* </code>
*
* @param array $supported An array of supported charsets
* @param string $default The default charset to use if none is found.
*
* @return string The negotiated language result or the supplied default.
- * @static
* @author Philippe Jausions <jausions@php.net>
- * @access public
- * @since 1.4.1
*/
- function negotiateCharset($supported, $default = 'ISO-8859-1')
+ public function negotiateCharset($supported, $default = 'ISO-8859-1')
{
$supp = array();
foreach ($supported as $charset) {
@@ -169,7 +166,7 @@ function negotiateCharset($supported, $default = 'ISO-8859-1')
}
if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
- $match = HTTP2::_matchAccept($_SERVER['HTTP_ACCEPT_CHARSET'],
+ $match = $this->_matchAccept($_SERVER['HTTP_ACCEPT_CHARSET'],
$supp);
if (!is_null($match)) {
return $match;
@@ -188,25 +185,23 @@ function negotiateCharset($supported, $default = 'ISO-8859-1')
*
* <code>
* require_once 'HTTP2.php';
+ * $http = new HTTP2();
* $contentType = array(
* 'application/xhtml+xml',
* 'application/xml',
* 'text/html',
* 'text/plain',
* );
- * $mime = HTTP2::negotiateContentType($contentType);
+ * $mime = $http->negotiateContentType($contentType);
* </code>
*
* @param array $supported An associative array of supported MIME types.
* @param string $default The default type to use if none match.
*
* @return string The negotiated MIME type result or the supplied default.
- * @static
* @author Philippe Jausions <jausions@php.net>
- * @access public
- * @since 1.4.1
*/
- function negotiateMimeType($supported, $default)
+ public function negotiateMimeType($supported, $default)
{
$supp = array();
foreach ($supported as $type) {
@@ -218,7 +213,7 @@ function negotiateMimeType($supported, $default)
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
- $accepts = HTTP2::_sortAccept($_SERVER['HTTP_ACCEPT']);
+ $accepts = $this->_sortAccept($_SERVER['HTTP_ACCEPT']);
foreach ($accepts as $type => $q) {
if (substr($type, -2) != '/*') {
@@ -252,12 +247,10 @@ function negotiateMimeType($supported, $default)
* @param array $supported A list of supported values
*
* @return string|NULL a matched option, or NULL if no match
- * @access private
- * @static
*/
- function _matchAccept($header, $supported)
+ protected function _matchAccept($header, $supported)
{
- $matches = HTTP2::_sortAccept($header);
+ $matches = $this->sortAccept($header);
foreach ($matches as $key => $q) {
if (isset($supported[$key])) {
return $supported[$key];
@@ -276,10 +269,8 @@ function _matchAccept($header, $supported)
* @param string $header The HTTP "Accept" header to parse
*
* @return array a sorted list of "accept" options
- * @access private
- * @static
*/
- function _sortAccept($header)
+ protected function _sortAccept($header)
{
$matches = array();
foreach (explode(',', $header) as $option) {
@@ -337,15 +328,15 @@ function head($url, $timeout = 10)
{
$p = parse_url($url);
if (!isset($p['scheme'])) {
- $p = parse_url(HTTP2::absoluteURI($url));
+ $p = parse_url($this->absoluteURI($url));
} elseif ($p['scheme'] != 'http') {
- return HTTP2::raiseError('Unsupported protocol: '. $p['scheme']);
+ throw new InvalidArgumentException('Unsupported protocol: '. $p['scheme']);
}
$port = isset($p['port']) ? $p['port'] : 80;
if (!$fp = @fsockopen($p['host'], $port, $eno, $estr, $timeout)) {
- return HTTP2::raiseError("Connection error: $estr ($eno)");
+ throw new HTTP2_Exception("Connection error: $estr ($eno)");
}
$path = !empty($p['path']) ? $p['path'] : '/';
@@ -389,8 +380,6 @@ function head($url, $timeout = 10)
*
* @return boolean Returns TRUE on succes (or exits) or FALSE if headers
* have already been sent.
- * @static
- * @access public
*/
function redirect($url, $exit = true, $rfc2616 = false)
{
@@ -398,7 +387,7 @@ function redirect($url, $exit = true, $rfc2616 = false)
return false;
}
- $url = HTTP2::absoluteURI($url);
+ $url = $this->absoluteURI($url);
header('Location: '. $url);
if ($rfc2616 && isset($_SERVER['REQUEST_METHOD'])
@@ -440,10 +429,8 @@ function redirect($url, $exit = true, $rfc2616 = false)
*
* @return string The absolute URI.
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
- * @static
- * @access public
*/
- function absoluteURI($url = null, $protocol = null, $port = null)
+ public function absoluteURI($url = null, $protocol = null, $port = null)
{
// filter CR/LF
$url = str_replace(array("\r", "\n"), ' ', $url);
@@ -525,24 +512,4 @@ function absoluteURI($url = null, $protocol = null, $port = null)
return $server . $path . $url;
}
-
- /**
- * Raise Error
- *
- * Lazy raising of PEAR_Errors.
- *
- * @param mixed $error Error
- * @param integer $code Error code
- *
- * @return object PEAR_Error
- * @static
- * @access protected
- */
- function raiseError($error = null, $code = null)
- {
- include_once 'PEAR.php';
- return PEAR::raiseError($error, $code);
- }
-}
-
-?>
+}
View
2  HTTP2/Exception.php
@@ -0,0 +1,2 @@
+<?php
+class HTTP2_Exception extends Exception {}
View
53 package.xml
@@ -19,7 +19,7 @@ language negotiation or HTTP redirection.</description>
<active>yes</active>
</lead>
<date>2012-01-16</date>
- <time>08:32:47</time>
+ <time>08:49:13</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
@@ -30,31 +30,28 @@ language negotiation or HTTP redirection.</description>
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
<notes>
-* Fixed bug #7130 - HTTP2::absoluteUri(&quot;?foo&quot;) loses path
-* Fixed bug #12672 - PHP_SELF ending on / causes incorrect redirects
-* Fixed bug #12571 - Wrong license in package.xml
-* Fixed bug #12759 - DOS linebreaks
-* Fixed req #9148 - Added negotiateCharset() method
-* Fixed req #11060 - Added negotiateMimeType() method
-* Added regression tests
-* Bump to package.xml v2.0
-* Added failover JavaScript for redirect()
+Fork from HTTP
+PHP5-ify
+Make API non static
</notes>
<contents>
<dir baseinstalldir="/" name="/">
- <file baseinstalldir="/" md5sum="4d059ea386607aceb0336e67a86ca558" name="/tests/absoluteURI.inc" role="data" />
- <file baseinstalldir="/" md5sum="0db97266e5f5f294f2a15c6b36d72813" name="/tests/negotiateCharset.phpt" role="data" />
- <file baseinstalldir="/" md5sum="ec15a9cc3fd02bf6467fb79a2cbabaef" name="/tests/negotiateCharset2.phpt" role="data" />
- <file baseinstalldir="/" md5sum="5b7f17cf506e13ed2c877ffdc91ed3d3" name="/tests/negotiateLanguage.phpt" role="data" />
- <file baseinstalldir="/" md5sum="7ba93e6f666001c3a660eca2334d12cb" name="/tests/negotiateMimeType.phpt" role="data" />
- <file baseinstalldir="/" md5sum="892ff27a8c6bc88b4c960fbaa435e9c4" name="/tests/test1a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="b49e8a91bca63000f1f0529264d23509" name="/tests/test2a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="25fc92b0202bbce0dfb83541b95b0af4" name="/tests/test3a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="7a3416157e875847f4806a63af709d12" name="/tests/test4a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="2999ad352f432b280f630794bddc224d" name="/tests/test5a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="a5f75a6adfaf80dbfa53e46f0438fa23" name="/tests/test6a.phpt" role="data" />
- <file baseinstalldir="/" md5sum="265297b2a37a082054987b4357177b9c" name="HTTP2.php" role="php" />
+ <file baseinstalldir="/" md5sum="a34a19790a8831b38419313c9c10dfda" name="/HTTP2/Exception.php" role="php" />
+ <file baseinstalldir="/" md5sum="6b330e9bba20b1dcef8377079ead6081" name="/tests/absoluteURI.inc" role="data" />
+ <file baseinstalldir="/" md5sum="838e1ec4a549a105bda7cb3708e17bca" name="/tests/negotiateCharset.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="7bed1d59960f30ad959abc59b62a6787" name="/tests/negotiateCharset2.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="a8fed2e334ab0eff115c2d3a047b4893" name="/tests/negotiateLanguage.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="93bb4a04a190cb7815af8e52f83cf91b" name="/tests/negotiateMimeType.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="dfe5128e00b9c5b91afa186bc2989757" name="/tests/test1a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="df84a961cad11792302ea7facb70eff0" name="/tests/test2a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="96b47dc38996a5970b016e5b555eed6e" name="/tests/test3a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="cb88ce1aae8e8b662acb27cfb2b6f3b2" name="/tests/test4a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="9776763b4f9d8e4f9b06b4bf5db46dd2" name="/tests/test5a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="2a46d2f6421ae83304a47cb8893dbda5" name="/tests/test6a.phpt" role="data" />
+ <file baseinstalldir="/" md5sum="4d1a5edebb6d0278d8a7eb6450bbc3ff" name="build.xml" role="data" />
+ <file baseinstalldir="/" md5sum="c6097d16e897dece16534139f11c2d61" name="HTTP2.php" role="php" />
<file baseinstalldir="/" md5sum="cd6a3937d363e0a0ca538cadfde7b9bf" name="LICENSE" role="data" />
+ <file baseinstalldir="/" md5sum="a493bce55f6aa1476d12fa0c707a95e2" name="phpunit.xml" role="data" />
<file baseinstalldir="/" md5sum="f006ef26c9f7d6dd88cabcb18a774b86" name="README" role="data" />
</dir>
</contents>
@@ -89,15 +86,9 @@ language negotiation or HTTP redirection.</description>
<date>2012-01-16</date>
<license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
<notes>
-* Fixed bug #7130 - HTTP2::absoluteUri(&quot;?foo&quot;) loses path
-* Fixed bug #12672 - PHP_SELF ending on / causes incorrect redirects
-* Fixed bug #12571 - Wrong license in package.xml
-* Fixed bug #12759 - DOS linebreaks
-* Fixed req #9148 - Added negotiateCharset() method
-* Fixed req #11060 - Added negotiateMimeType() method
-* Added regression tests
-* Bump to package.xml v2.0
-* Added failover JavaScript for redirect()
+Fork from HTTP
+PHP5-ify
+Make API non static
</notes>
</release>
</changelog>
View
3  tests/absoluteURI.inc
@@ -34,11 +34,12 @@ $tests = array(
array('page.html', 'https', 8888), // Force HTTPS / port 8888
);
+$http = new HTTP2();
foreach ($tests as $test) {
list($page, $protocol, $port) = $test;
echo sprintf('%-20s', implode('|', $test)).' => '
- .HTTP2::absoluteURI($page, $protocol, $port, HTTP2_RELATIVETOSCRIPT)
+ .$http->absoluteURI($page, $protocol, $port, HTTP2_RELATIVETOSCRIPT)
."\n";
}
View
4 tests/negotiateCharset.phpt
@@ -54,8 +54,10 @@ $sets = array(
5 => array(
),
);
+
+$http = new HTTP2();
foreach ($sets as $i => $supported) {
- echo $i.' => '.HTTP2::negotiateCharset($supported, 'us-ascii')
+ echo $i.' => '. $http->negotiateCharset($supported, 'us-ascii')
."\n";
}
View
3  tests/negotiateCharset2.phpt
@@ -54,8 +54,9 @@ $sets = array(
5 => array(
),
);
+$http = new HTTP2();
foreach ($sets as $i => $supported) {
- echo $i.' => '.HTTP2::negotiateCharset($supported, 'us-ascii')
+ echo $i.' => '. $http->negotiateCharset($supported, 'us-ascii')
."\n";
}
View
3  tests/negotiateLanguage.phpt
@@ -66,8 +66,9 @@ $sets = array(
7 => array(
),
);
+$http = new HTTP2();
foreach ($sets as $i => $languages) {
- echo $i.' => '.HTTP2::negotiateLanguage($languages, 'de')."\n";
+ echo $i.' => '. $http->negotiateLanguage($languages, 'de')."\n";
}
?>
View
4 tests/negotiateMimeType.phpt
@@ -85,8 +85,10 @@ $sets = array(
9 => array(
),
);
+
+$http = new HTTP2();
foreach ($sets as $i => $supported) {
- echo $i.' => '.HTTP2::negotiateMimeType($supported, 'application/octet-stream')
+ echo $i.' => '.$http->negotiateMimeType($supported, 'application/octet-stream')
."\n";
}
Please sign in to comment.
Something went wrong with that request. Please try again.