33use alsvanzelf \jsonapi \Document ;
44use alsvanzelf \jsonapi \ResourceDocument ;
55use alsvanzelf \jsonapi \interfaces \ExtensionInterface ;
6+ use alsvanzelf \jsonapi \interfaces \HasAttributesInterface ;
7+ use alsvanzelf \jsonapi \interfaces \HasExtensionMembersInterface ;
68use alsvanzelf \jsonapi \interfaces \ProfileInterface ;
79use alsvanzelf \jsonapi \interfaces \ResourceInterface ;
810use alsvanzelf \jsonapi \objects \ResourceIdentifierObject ;
11+ use alsvanzelf \jsonapi \objects \ResourceObject ;
912
1013ini_set ('display_errors ' , 1 );
1114error_reporting (-1 );
@@ -55,7 +58,7 @@ class ExampleDataset {
5558
5659 public static function getRecord ($ type , $ id ) {
5760 if (!isset (self ::$ records [$ type ][$ id ])) {
58- throw new Exception ('sorry, we have a limited dataset ' );
61+ throw new \ Exception ('sorry, we have a limited dataset ' );
5962 }
6063
6164 return self ::$ records [$ type ][$ id ];
@@ -121,6 +124,10 @@ public function getNamespace() {
121124 */
122125
123126 public function setVersion (ResourceInterface $ resource , $ version ) {
127+ if ($ resource instanceof HasExtensionMembersInterface === false ) {
128+ throw new \Exception ('resource doesn \'t have extension members ' );
129+ }
130+
124131 if ($ resource instanceof ResourceDocument) {
125132 $ resource ->getResource ()->addExtensionMember ($ this , 'id ' , $ version );
126133 }
@@ -143,9 +150,12 @@ public function getOfficialLink() {
143150 * optionally helpers for the specific profile
144151 */
145152
153+ /**
154+ * @param ResourceInterface&HasAttributesInterface $resource
155+ */
146156 public function setTimestamps (ResourceInterface $ resource , ?\DateTimeInterface $ created =null , ?\DateTimeInterface $ updated =null ) {
147- if ($ resource instanceof ResourceIdentifierObject ) {
148- throw new Exception ('cannot add attributes to identifier objects ' );
157+ if ($ resource instanceof HasAttributesInterface === false ) {
158+ throw new \ Exception ('cannot add attributes to identifier objects ' );
149159 }
150160
151161 $ timestamps = [];
@@ -156,6 +166,6 @@ public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $
156166 $ timestamps ['updated ' ] = $ updated ->format (\DateTime::ISO8601 );
157167 }
158168
159- $ resource ->add ('timestamps ' , $ timestamps );
169+ $ resource ->addAttribute ('timestamps ' , $ timestamps );
160170 }
161171}
0 commit comments