Skip to content

Commit a4de9e5

Browse files
committed
bug #7 Add support for statement version property (Jérôme Parmentier)
This PR was merged into the 2.1.x-dev branch. Discussion ---------- Add support for statement version property Commits ------- 82eeaab Add support for statement version property
2 parents 17be658 + 82eeaab commit a4de9e5

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ cache:
66
directories:
77
- $HOME/.composer/cache/files
88

9+
env:
10+
COMPOSER_OPTIONS="--prefer-stable"
11+
912
matrix:
1013
fast_finish: true
1114
include:
1215
- php: 5.6
13-
env: deps="low"
16+
env: COMPOSER_OPTIONS="--prefer-lowest --prefer-stable"
1417
- php: 7.0
1518
env: xdebug="yes"
1619
- php: 7.1
@@ -21,7 +24,7 @@ before_install:
2124
- composer require 'phpunit/phpunit:^4.8.35|^5.4.3|^6.0' --dev --no-update
2225

2326
install:
24-
- if [ "$deps" = "low" ]; then composer update --prefer-lowest --prefer-stable; else composer install; fi
27+
- composer update $COMPOSER_OPTIONS
2528

2629
script:
2730
- vendor/bin/phpspec run

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
2.1.0
55
-----
66

7+
* added missing support for statement versions
8+
79
* dropped support for PHP < 5.6
810

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

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
],
1414
"require": {
1515
"php": "^5.6 || ^7.0",
16-
"php-xapi/model": "^1.0 || ^2.0",
16+
"php-xapi/exception": "^0.2.0",
17+
"php-xapi/model": "^1.2 || ^2.1",
1718
"php-xapi/serializer": "^2.1.1",
1819
"symfony/serializer": "~2.8|~3.0"
1920
},

src/Normalizer/StatementNormalizer.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Xabbuh\XApi\Serializer\Symfony\Normalizer;
1313

14+
use Xabbuh\XApi\Common\Exception\UnsupportedStatementVersionException;
1415
use Xabbuh\XApi\Model\Statement;
1516
use Xabbuh\XApi\Model\StatementId;
1617

@@ -64,6 +65,10 @@ public function normalize($object, $format = null, array $context = array())
6465
$data['attachments'] = $this->normalizeAttribute($attachments, $format, $context);
6566
}
6667

68+
if (null !== $version = $object->getVersion()) {
69+
$data['version'] = $version;
70+
}
71+
6772
return $data;
6873
}
6974

@@ -80,6 +85,16 @@ public function supportsNormalization($data, $format = null)
8085
*/
8186
public function denormalize($data, $class, $format = null, array $context = array())
8287
{
88+
$version = null;
89+
90+
if (isset($data['version'])) {
91+
$version = $data['version'];
92+
93+
if (!preg_match('/^1\.0(?:\.\d+)?$/', $version)) {
94+
throw new UnsupportedStatementVersionException(sprintf('Statements at version "%s" are not supported.', $version));
95+
}
96+
}
97+
8398
$id = isset($data['id']) ? StatementId::fromString($data['id']) : null;
8499
$actor = $this->denormalizeData($data['actor'], 'Xabbuh\XApi\Model\Actor', $format, $context);
85100
$verb = $this->denormalizeData($data['verb'], 'Xabbuh\XApi\Model\Verb', $format, $context);
@@ -115,7 +130,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
115130
$attachments = $this->denormalizeData($data['attachments'], 'Xabbuh\XApi\Model\Attachment[]', $format, $context);
116131
}
117132

118-
return new Statement($id, $actor, $verb, $object, $result, $authority, $created, $stored, $statementContext, $attachments);
133+
return new Statement($id, $actor, $verb, $object, $result, $authority, $created, $stored, $statementContext, $attachments, $version);
119134
}
120135

121136
/**

0 commit comments

Comments
 (0)