1111
1212namespace Xabbuh \XApi \Serializer \Symfony \Normalizer ;
1313
14+ use Xabbuh \XApi \Common \Exception \UnsupportedStatementVersionException ;
1415use Xabbuh \XApi \Model \Statement ;
1516use 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