Skip to content

Commit ae11386

Browse files
committed
fix PHP 7.2 support
1 parent 82eeaab commit ae11386

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ matrix:
1717
- php: 7.0
1818
env: xdebug="yes"
1919
- php: 7.1
20+
- php: 7.2
2021

2122
before_install:
2223
- if [[ "$xdebug" != "yes" ]]; then phpenv config-rm xdebug.ini; fi

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CHANGELOG
1010

1111
* allow `2.x` releases of the `php-xapi/model` package too
1212

13+
* allow `3.x` releases of the `php-xapi/model` package too
14+
1315
2.0.0
1416
-----
1517

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": "^5.6 || ^7.0",
1616
"php-xapi/exception": "^0.2.0",
17-
"php-xapi/model": "^1.2 || ^2.1",
17+
"php-xapi/model": "^1.2 || ^2.1 || ^3.0",
1818
"php-xapi/serializer": "^2.1.1",
1919
"symfony/serializer": "~2.8|~3.0"
2020
},

src/Normalizer/ObjectNormalizer.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
use Xabbuh\XApi\Model\Activity;
1515
use Xabbuh\XApi\Model\IRI;
16-
use Xabbuh\XApi\Model\Object;
17-
use Xabbuh\XApi\Model\Statement;
16+
use Xabbuh\XApi\Model\Object as LegacyStatementObject;
1817
use Xabbuh\XApi\Model\StatementId;
18+
use Xabbuh\XApi\Model\StatementObject;
1919
use Xabbuh\XApi\Model\StatementReference;
2020
use Xabbuh\XApi\Model\SubStatement;
2121

@@ -78,7 +78,7 @@ public function normalize($object, $format = null, array $context = array())
7878
*/
7979
public function supportsNormalization($data, $format = null)
8080
{
81-
return $data instanceof Object;
81+
return $data instanceof LegacyStatementObject || $data instanceof StatementObject;
8282
}
8383

8484
/**
@@ -110,7 +110,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
110110
*/
111111
public function supportsDenormalization($data, $type, $format = null)
112112
{
113-
return 'Xabbuh\XApi\Model\Activity' === $type || 'Xabbuh\XApi\Model\Object' === $type || 'Xabbuh\XApi\Model\StatementReference' === $type || 'Xabbuh\XApi\Model\SubStatement' === $type;
113+
return in_array($type, array(Activity::class, LegacyStatementObject::class, StatementObject::class, StatementReference::class, SubStatement::class), true);
114114
}
115115

116116
private function denormalizeActivity(array $data, $format = null, array $context = array())
@@ -128,7 +128,13 @@ private function denormalizeSubStatement(array $data, $format = null, array $co
128128
{
129129
$actor = $this->denormalizeData($data['actor'], 'Xabbuh\XApi\Model\Actor', $format, $context);
130130
$verb = $this->denormalizeData($data['verb'], 'Xabbuh\XApi\Model\Verb', $format, $context);
131-
$object = $this->denormalizeData($data['object'], 'Xabbuh\XApi\Model\Object', $format, $context);
131+
132+
if (class_exists(StatementObject::class)) {
133+
$object = $this->denormalizeData($data['object'], StatementObject::class, $format, $context);
134+
} else {
135+
$object = $this->denormalizeData($data['object'], LegacyStatementObject::class, $format, $context);
136+
}
137+
132138
$result = null;
133139
$statementContext = null;
134140

src/Normalizer/StatementNormalizer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Xabbuh\XApi\Serializer\Symfony\Normalizer;
1313

1414
use Xabbuh\XApi\Common\Exception\UnsupportedStatementVersionException;
15+
use Xabbuh\XApi\Model\Object as LegacyStatementObject;
1516
use Xabbuh\XApi\Model\Statement;
1617
use Xabbuh\XApi\Model\StatementId;
18+
use Xabbuh\XApi\Model\StatementObject;
1719

1820
/**
1921
* Normalizes and denormalizes xAPI statements.
@@ -98,7 +100,13 @@ public function denormalize($data, $class, $format = null, array $context = arra
98100
$id = isset($data['id']) ? StatementId::fromString($data['id']) : null;
99101
$actor = $this->denormalizeData($data['actor'], 'Xabbuh\XApi\Model\Actor', $format, $context);
100102
$verb = $this->denormalizeData($data['verb'], 'Xabbuh\XApi\Model\Verb', $format, $context);
101-
$object = $this->denormalizeData($data['object'], 'Xabbuh\XApi\Model\Object', $format, $context);
103+
104+
if (class_exists(StatementObject::class)) {
105+
$object = $this->denormalizeData($data['object'], StatementObject::class, $format, $context);
106+
} else {
107+
$object = $this->denormalizeData($data['object'], LegacyStatementObject::class, $format, $context);
108+
}
109+
102110
$result = null;
103111
$authority = null;
104112
$created = null;

0 commit comments

Comments
 (0)