Skip to content

Commit b873929

Browse files
authored
Merge pull request #1 from xp-forge/refactor/php72
Make compatible with newer XP / PHP versions
2 parents e20b580 + ef0699e commit b873929

18 files changed

+162
-72
lines changed

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ language: php
55
php:
66
- 5.6
77
- 7.0
8+
- 7.1
9+
- 7.2
10+
- 7.3
811
- hhvm
912
- nightly
1013

1114
matrix:
1215
allow_failures:
16+
- php: hhvm
1317
- php: nightly
1418

1519
before_script:
16-
- wget 'https://github.com/xp-framework/xp-runners/releases/download/v6.3.0/setup' -O - | php
20+
- curl -sSL https://dl.bintray.com/xp-runners/generic/xp-run-master.sh > xp-run
1721
- composer install --prefer-dist
1822
- echo "vendor/autoload.php" > composer.pth
19-
- echo "use=vendor/xp-framework/core" > xp.ini
20-
- echo "[runtime]" >> xp.ini
21-
- echo "date.timezone=Europe/Berlin" >> xp.ini
22-
23-
script:
2423
- wget 'https://github.com/json-patch/json-patch-tests/archive/master.zip' -O master.zip
2524
- unzip master.zip && rm master.zip
26-
- ./unittest src/test/php -a json-patch-tests-master/
25+
26+
script:
27+
- sh xp-run xp.unittest.TestRunner src/test/php -a json-patch-tests-master/

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"description" : "Implements JSON patch documents described in RFC #6902",
77
"keywords": ["module", "xp"],
88
"require" : {
9-
"xp-framework/core": "^7.0 | ^6.3",
9+
"xp-framework/core": "^9.0 | ^8.0 | ^7.0 | ^6.3",
1010
"php" : ">=5.6.0"
1111
},
1212
"require-dev" : {
13-
"xp-framework/unittest": "^7.0 | ^6.5",
14-
"xp-forge/json": "^2.0"
13+
"xp-framework/unittest": "^9.0 | ^8.0 | ^7.0 | ^6.5",
14+
"xp-framework/io-collections": "^8.0 | ^7.0 | ^6.5",
15+
"xp-forge/json": "^3.0 | ^2.0"
1516
},
1617
"autoload" : {
1718
"files" : ["src/main/php/autoload.php"]

src/main/php/text/json/patch/AddOperation.class.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function applyTo(&$target) {
4040
return $this->path->resolve($target)->add($this->value);
4141
}
4242

43+
/** @return string */
44+
public function hashCode() {
45+
return 'A'.Objects::hashOf($this->path.$this->value);
46+
}
47+
4348
/** @return string */
4449
public function toString() {
4550
return nameof($this).'(add '.$this->path.' => '.Objects::stringOf($this->value).')';
@@ -48,10 +53,13 @@ public function toString() {
4853
/**
4954
* Returns whether a given value is equal to this results instance
5055
*
51-
* @param var $cmp
52-
* @return bool
56+
* @param var $value
57+
* @return int
5358
*/
54-
public function equals($cmp) {
55-
return $cmp instanceof self && $this->path->equals($cmp->path) && Objects::equal($this->value, $cmp->value);
59+
public function compareTo($value) {
60+
return $value instanceof self
61+
? Objects::compare($this->path, $value->path)
62+
: 1
63+
;
5664
}
5765
}

src/main/php/text/json/patch/Address.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace text\json\patch;
22

3-
abstract class Address extends \lang\Object {
3+
abstract class Address {
44
protected static $null= null;
55
protected $exists, $parent;
66
public $reference;

src/main/php/text/json/patch/Applied.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @see xp://text.json.patch.Operation#applyTo()
77
*/
8-
abstract class Applied extends \lang\Object {
8+
abstract class Applied {
99
public static $CLEANLY;
1010

1111
static function __static() {

src/main/php/text/json/patch/Changes.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @test xp://text.json.patch.unittest.ChangesTest
88
* @test xp://text.json.patch.unittest.ApplyTest
99
*/
10-
class Changes extends \lang\Object {
10+
class Changes {
1111
private $operations= [];
1212

1313
/**

src/main/php/text/json/patch/CopyOperation.class.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace text\json\patch;
22

3+
use util\Objects;
4+
35
/**
46
* The "copy" operation copies the value at a specified location to the
57
* target location.
@@ -40,6 +42,11 @@ public function applyTo(&$target) {
4042
return new PathDoesNotExist($this->from);
4143
}
4244

45+
/** @return string */
46+
public function hashCode() {
47+
return 'C'.Objects::hashOf($this->path.$this->value);
48+
}
49+
4350
/** @return string */
4451
public function toString() {
4552
return nameof($this).'(copy '.$this->from.' -> '.$this->path.')';
@@ -48,10 +55,13 @@ public function toString() {
4855
/**
4956
* Returns whether a given value is equal to this results instance
5057
*
51-
* @param var $cmp
52-
* @return bool
58+
* @param var $value
59+
* @return int
5360
*/
54-
public function equals($cmp) {
55-
return $cmp instanceof self && $this->path->equals($cmp->path) && $this->from->equals($cmp->from);
61+
public function compareTo($value) {
62+
return $value instanceof self
63+
? Objects::compare([$this->path, $this->from], [$value->path, $value->from])
64+
: 1
65+
;
5666
}
5767
}
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php namespace text\json\patch;
22

3-
abstract class Error extends Applied {
3+
use lang\Value;
4+
5+
abstract class Error extends Applied implements Value {
46

57
static function __static() { }
68

@@ -10,6 +12,11 @@ public function isError() { return true; }
1012
/** @return string */
1113
public abstract function message();
1214

15+
/** @return string */
16+
public function hashCode() {
17+
return 'E'.md5($this->message());
18+
}
19+
1320
/** @return string */
1421
public function toString() {
1522
return nameof($this).'('.$this->message().')';
@@ -18,10 +25,10 @@ public function toString() {
1825
/**
1926
* Returns whether a given error is equal to this results instance
2027
*
21-
* @param var $cmp
22-
* @return bool
28+
* @param var $value
29+
* @return int
2330
*/
24-
public function equals($cmp) {
25-
return $cmp instanceof self && $this->message() === $cmp->message();
31+
public function compareTo($value) {
32+
return $value instanceof self ? strcmp($this->message(), $value->message()) : 1;
2633
}
2734
}

src/main/php/text/json/patch/Failure.class.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace text\json\patch;
22

3+
use util\Objects;
4+
35
/**
46
* Indicates failure result
57
*/
@@ -21,18 +23,23 @@ public function successful() { return false; }
2123
/** @return text.json.patch.Error */
2224
public function error() { return $this->error; }
2325

26+
/** @return string */
27+
public function hashCode() {
28+
return '-'.Objects::hashOf($this->value);
29+
}
30+
2431
/** @return string */
2532
public function toString() {
26-
return nameof($this).'(failure -> '.$this->error->message().')';
33+
return nameof($this).'(failure -> '.$this->error->message().')';
2734
}
2835

2936
/**
30-
* Returns whether a given error is equal to this results instance
37+
* Comparison
3138
*
32-
* @param var $cmp
33-
* @return bool
39+
* @param var $value
40+
* @return int
3441
*/
35-
public function equals($cmp) {
36-
return $cmp instanceof self && $this->error->equals($cmp->error);
42+
public function compareTo($value) {
43+
return $value instanceof self ? Objects::compare($this->error, $value->error) : 1;
3744
}
3845
}

src/main/php/text/json/patch/MoveOperation.class.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace text\json\patch;
22

3+
use util\Objects;
4+
35
/**
46
* The "move" operation removes the value at a specified location and
57
* adds it to the target location.
@@ -40,6 +42,11 @@ public function applyTo(&$target) {
4042
return $from->remove()->then(function() use($to, $value) { return $to->add($value); });
4143
}
4244

45+
/** @return string */
46+
public function hashCode() {
47+
return 'M'.Objects::hashOf($this->path.$this->value);
48+
}
49+
4350
/** @return string */
4451
public function toString() {
4552
return nameof($this).'(move '.$this->from.' -> '.$this->path.')';
@@ -48,10 +55,13 @@ public function toString() {
4855
/**
4956
* Returns whether a given value is equal to this results instance
5057
*
51-
* @param var $cmp
52-
* @return bool
58+
* @param var $value
59+
* @return int
5360
*/
54-
public function equals($cmp) {
55-
return $cmp instanceof self && $this->path->equals($cmp->path) && $this->from->equals($cmp->from);
61+
public function compareTo($value) {
62+
return $value instanceof self
63+
? Objects::compare([$this->path, $this->from], [$value->path, $value->from])
64+
: 1
65+
;
5666
}
5767
}

0 commit comments

Comments
 (0)