Skip to content

Commit

Permalink
Merge pull request #20 from xp-framework/refactor/xp9
Browse files Browse the repository at this point in the history
XP9 Compatibility
  • Loading branch information
thekid authored Jun 19, 2017
2 parents 2eaaa8a + 510d429 commit 4e17023
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 125 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ HTTP protocol support for the XP Framework ChangeLog

## ?.?.? / ????-??-??

## 9.0.0 / 2017-06-20

* Merged PR #20: XP9 Compatibility - @thekid

## 8.0.2 / 2017-06-05

* Fixed `Fatal error (Class 'peer\Header' not found)` - @thekid
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"description" : "HTTP protocol support for the XP Framework",
"keywords": ["module", "xp"],
"require" : {
"xp-framework/core": "^8.0 | ^7.0 | ^6.5",
"xp-framework/logging": "^7.0 | ^6.5",
"xp-framework/networking": "^8.0 | ^7.0 | ^6.6",
"xp-framework/core": "^9.0 | ^8.0 | ^7.0 | ^6.5",
"xp-framework/logging": "^8.0 | ^7.0 | ^6.5",
"xp-framework/networking": "^9.0 | ^8.0 | ^7.0 | ^6.6",
"php": ">=5.6.0"
},
"require-dev" : {
"xp-framework/unittest": "^7.0 | ^6.5"
"xp-framework/unittest": "^9.0 | ^8.0 | ^7.0 | ^6.5"
},
"autoload" : {
"files" : ["src/main/php/autoload.php"]
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/Authorization.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace peer\http;

abstract class Authorization extends \lang\Object {
abstract class Authorization {
protected $username, $password;

/** @return string */
Expand Down
49 changes: 25 additions & 24 deletions src/main/php/peer/http/DigestAuthorization.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php namespace peer\http;

use lang\Object;
use util\Objects;
use util\Secret;
use lang\Value;
use lang\IllegalStateException;
use lang\MethodNotImplementedException;

Expand All @@ -19,7 +20,7 @@
* @see rfc://2617
* @see https://en.wikipedia.org/wiki/Digest_access_authentication
*/
class DigestAuthorization extends Authorization {
class DigestAuthorization extends Authorization implements Value {

/* Server values */
private $realm; // Realm
Expand All @@ -39,7 +40,7 @@ class DigestAuthorization extends Authorization {
* @param string $nonce
* @param string $opaque
*/
public function __construct($realm, $qop, $nonce, $opaque) {
public function __construct($realm, $qop, $nonce, $opaque= null) {
$this->realm= $realm;
$this->qop= $qop;
$this->nonce= $nonce;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function getValueRepresentation($method, $requestUri) {
'response' => $this->hashFor($method, $requestUri)
];

if (sizeof($this->opaque)) {
if (null !== $this->opaque) {
$parts['opaque']= $this->opaque;
}

Expand Down Expand Up @@ -204,33 +205,33 @@ public function cnonce($c= null) {
$this->cnonce= $c;
}

/**
* Check if instance is equal to this instance
*
* @param lang.Generic $o
* @return boolean
*/
public function equals($o) {
if (!$o instanceof self) return false;

return (
$o->realm === $this->realm &&
$o->qop === $this->qop &&
$o->nonce === $this->nonce &&
$o->opaque === $this->opaque
);
/** @return string */
public function hashCode() {
return md5($this->realm.'.'.$this->qop.'.'.$this->nonce.'.'.$this->opaque);
}

/**
* Retrieve string representation
*
* @return string
*/
/** @return string */
public function toString() {
$s= nameof($this).' ('.$this->hashCode().") {\n";
foreach (['realm', 'qop', 'nonce', 'opaque', 'username'] as $attr) {
$s.= sprintf(" [ %8s ] %s\n", $attr, \xp::stringOf($this->{$attr}));
}
return $s.="}\n";
}

/**
* Compare
*
* @param var $value
* @return int
*/
public function compareTo($value) {
return $value instanceof self
? Objects::compare(
[$this->realm, $this->qop, $this->nonce, $this->opaque],
[$value->realm, $value->qop, $value->nonce, $value->opaque]
)
: 1
;
}
}
2 changes: 1 addition & 1 deletion src/main/php/peer/http/FormData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @test xp://peer.http.unittest.FormDataRequestTest
*/
class FormData extends \lang\Object {
class FormData {
const
CRLF = "\r\n",
DEFAULT_CONTENTTYPE = 'text/plain',
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpConnection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @see rfc://2616
* @test xp://net.xp_framework.unittest.peer.HttpTest
*/
class HttpConnection extends \lang\Object implements Traceable {
class HttpConnection implements Traceable {
protected
$url = null,
$transport = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpConstants.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP methods
* @see http://tools.ietf.org/html/rfc6585
*/
class HttpConstants extends \lang\Object {
class HttpConstants {
const
GET = 'GET',
POST = 'POST',
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpInputStream.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @test xp://peer.http.unittest.HttpInputStreamTest
*/
class HttpInputStream extends \lang\Object implements InputStream {
class HttpInputStream implements InputStream {
protected
$response = null,
$buffer = '',
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpProxy.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @see xp://peer.http.proxy.Excludes
* @test xp://peer.http.unittest.HttpProxyTest
*/
class HttpProxy extends \lang\Object {
class HttpProxy {
const NONE = null;

protected $host, $port, $excludes;
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpRequest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see xp://peer.http.HttpConnection
* @see rfc://2616
*/
class HttpRequest extends \lang\Object {
class HttpRequest {
public
$url = null,
$method = HttpConstants::GET,
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpRequestFactory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @see xp://peer.http.HttpConnection
*/
class HttpRequestFactory extends \lang\Object {
class HttpRequestFactory {

/**
* Factory method
Expand Down
42 changes: 25 additions & 17 deletions src/main/php/peer/http/HttpResponse.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace peer\http;

use io\streams\InputStream;
use lang\Value;
use util\Objects;

/**
* HTTP response
Expand All @@ -9,7 +11,7 @@
* @test xp://peer.http.unittest.HttpResponseTest
* @test xp://peer.http.unittest.HttpInputStreamTest
*/
class HttpResponse extends \lang\Object {
class HttpResponse implements Value {
public
$statuscode = 0,
$message = '',
Expand Down Expand Up @@ -198,22 +200,12 @@ public function getHeaderString() {
return $s."\r\n";
}

/**
* Return nice string representation
*
* Example:
* <pre>
* peer.http.HttpResponse (HTTP/1.1 300 Multiple Choices) {
* [Date ] Sat, 01 Feb 2003 01:27:26 GMT
* [Server ] Apache/1.3.27 (Unix)
* [Connection ] close
* [Transfer-Encoding ] chunked
* [Content-Type ] text/html; charset=iso-8859-1
* }
* </pre>
*
* @return toString
*/
/** @return string */
public function hashCode() {
return Objects::hashOf([$this->version, $this->statuscode, $this->message, $this->headers]);
}

/** @return string */
public function toString() {
$h= '';
foreach ($this->headers as $k => $v) {
Expand All @@ -229,6 +221,22 @@ public function toString() {
);
}

/**
* Compare
*
* @param var $value
* @return int
*/
public function compareTo($value) {
return $value instanceof self
? Objects::compare(
[$this->version, $this->statuscode, $this->message, $this->headers],
[$value->version, $value->statuscode, $value->message, $value->headers]
)
: 1
;
}

/**
* Get HTTP statuscode
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpTransport.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see xp://peer.http.HttpConnection
* @test xp://peer.http.unittest.HttpTransportTest
*/
abstract class HttpTransport extends \lang\Object {
abstract class HttpTransport {
protected static $transports= [];
protected static $settings;
protected $proxy= null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/HttpUtil.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @see xp://peer.http.HttpConnection
* @purpose Utility class
*/
class HttpUtil extends \lang\Object {
class HttpUtil {

/**
* Fetch an URL's content. Follows redirects up until the defined
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/RequestData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @see xp://peer.http.HttpRequest#setParameters
*/
class RequestData extends \lang\Object {
class RequestData {
public $data;

/**
Expand Down
64 changes: 0 additions & 64 deletions src/main/php/peer/http/package-info.xp

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/php/peer/http/proxy/Excludes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @see xp://peer.http.HttpProxy
*/
class Excludes extends \lang\Object {
class Excludes {
protected $patterns;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/peer/http/proxy/ProxySettings.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use peer\http\HttpProxy;

abstract class ProxySettings extends \lang\Object {
abstract class ProxySettings {
protected $proxies;
protected $excludes;
protected $detected;
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/peer/http/unittest/HeaderTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function string_representation() {
# [new Header('Accept', '*/*'), new Header('Accept', '*/*'), 0],
# [new Header('ACCEPT', '*/*'), new Header('Accept', '*/*'), 0]
#])]
public function compareTo($a, $b, $expect) {
public function compare($a, $b, $expect) {
$this->assertEquals($expect, $a->compareTo($b));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function send(\peer\http\HttpRequest $request, $timeout= 60, $connecttime

#[@test, @expect(IllegalArgumentException::class)]
public function registerIncorrectClass() {
HttpTransport::register('irrelevant', $this->getClass());
HttpTransport::register('irrelevant', typeof($this));
}

#[@test]
Expand Down
Loading

0 comments on commit 4e17023

Please sign in to comment.