File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -29,11 +29,13 @@ class Context
2929 private ?array $ body ;
3030 private ?string $ path ;
3131
32+ private WeakMap $ endpoints ;
3233 private WeakMap $ fields ;
3334 private WeakMap $ sparseFields ;
3435
3536 public function __construct (public JsonApi $ api , public ServerRequestInterface $ request )
3637 {
38+ $ this ->endpoints = new WeakMap ();
3739 $ this ->fields = new WeakMap ();
3840 $ this ->sparseFields = new WeakMap ();
3941
@@ -88,6 +90,11 @@ public function resource(string $type): Resource
8890 return $ this ->api ->getResource ($ type );
8991 }
9092
93+ public function endpoints (Collection $ collection ): array
94+ {
95+ return $ this ->endpoints [$ collection ] ??= $ collection ->endpoints ();
96+ }
97+
9198 /**
9299 * Get the fields for the given resource, keyed by name.
93100 *
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ private function addToMap(Context $context): array
5757 foreach ($ context ->api ->getResourceCollections ($ resource ->type ()) as $ collection ) {
5858 $ collectionContext = $ context ->withCollection ($ collection );
5959
60- foreach ($ collection ->endpoints () as $ endpoint ) {
60+ foreach ($ context ->endpoints ($ collection ) as $ endpoint ) {
6161 if ($ endpoint instanceof ResourceEndpoint) {
6262 if ($ links = $ endpoint ->resourceLinks ($ model , $ collectionContext )) {
6363 $ this ->map [$ key ]['links ' ] ??= [];
You can’t perform that action at this time.
0 commit comments