File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,17 @@ private function enforceFullLinkage()
109109 return ;
110110 }
111111 foreach ($ this ->included as $ included_resource ) {
112- if (! $ this ->hasLinkTo ($ included_resource )) {
113- throw new \ LogicException ( " Full linkage is required for $ included_resource " ) ;
112+ if ($ this ->hasLinkTo ($ included_resource )) {
113+ continue ;
114114 }
115+ /** @var IdentifiableResource $another_included_resource */
116+ foreach ($ this ->included as $ another_included_resource ) {
117+ if ($ another_included_resource !== $ included_resource
118+ && $ another_included_resource ->identifies ($ included_resource )) {
119+ continue 2 ;
120+ }
121+ }
122+ throw new \LogicException ("Full linkage is required for $ included_resource " );
115123 }
116124 }
117125
Original file line number Diff line number Diff line change @@ -113,6 +113,28 @@ public function testIncludedResourceMayBeIdentifiedByPrimaryData()
113113 $ this ->assertCanBeBuilt ($ doc );
114114 }
115115
116+ public function testIncludedResourceMayBeIdentifiedByAnotherIncludedResource ()
117+ {
118+ /**
119+ * BasketID identifies included BasketObject
120+ * BasketObject identifies included AppleObject
121+ */
122+ $ apple = new ResourceObject ('apples ' , '1 ' );
123+ $ apple ->setAttribute ('color ' , 'red ' );
124+ $ basket = new ResourceObject ('basket ' , '1 ' );
125+ $ basket ->setRelationship (
126+ 'fruits ' ,
127+ Relationship::fromLinkage (
128+ Linkage::fromManyResourceIds (
129+ $ apple ->toId ()
130+ )
131+ )
132+ );
133+ $ doc = Document::fromResource ($ basket ->toId ());
134+ $ doc ->setIncluded ($ apple , $ basket );
135+ $ this ->assertCanBeBuilt ($ doc );
136+ }
137+
116138 private function convertToArray ($ object ): array
117139 {
118140 return json_decode (json_encode ($ object ), true );
You can’t perform that action at this time.
0 commit comments