This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +34
-14
lines changed Expand file tree Collapse file tree 5 files changed +34
-14
lines changed Original file line number Diff line number Diff line change 99
1010use Zend \Expressive \Hal \LinkCollection ;
1111
12- abstract class AbstractMetadata
12+ abstract class AbstractMetadata implements MetadataInterface
1313{
1414 use LinkCollection;
1515
@@ -22,4 +22,9 @@ public function getClass() : string
2222 {
2323 return $ this ->class ;
2424 }
25+
26+ public function hasReachedMaxDepth (int $ currentDepth ): bool
27+ {
28+ return false ;
29+ }
2530}
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Zend \Expressive \Hal \Metadata ;
5+
6+ interface MetadataInterface
7+ {
8+ /**
9+ * Returns the configured metadata class name
10+ *
11+ * @return string
12+ */
13+ public function getClass () : string ;
14+
15+ /**
16+ * Determines whenever the current depth level exceeds the allowed max depth
17+ *
18+ * @param int $currentDepth
19+ *
20+ * @return bool
21+ */
22+ public function hasReachedMaxDepth (int $ currentDepth ): bool ;
23+ }
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ public function setRouteParams(array $routeParams) : void
6767 $ this ->routeParams = $ routeParams ;
6868 }
6969
70- public function getMaxDepth ( ): int
70+ public function hasReachedMaxDepth ( int $ currentDepth ): bool
7171 {
72- return $ this ->maxDepth ;
72+ return $ currentDepth > $ this ->maxDepth ;
7373 }
7474}
Original file line number Diff line number Diff line change 1010use Psr \Http \Message \ServerRequestInterface ;
1111use Zend \Expressive \Hal \Metadata \AbstractCollectionMetadata ;
1212use Zend \Expressive \Hal \Metadata \AbstractMetadata ;
13- use Zend \Expressive \Hal \Metadata \RouteBasedResourceMetadata ;
1413use Zend \Expressive \Hal \ResourceGenerator ;
1514use Zend \Hydrator \ExtractionInterface ;
1615
@@ -39,14 +38,8 @@ private function extractInstance(
3938
4039 $ array = $ extractor ->extract ($ instance );
4140
42- if ($ metadata instanceof RouteBasedResourceMetadata) {
43- $ maxDepth = $ metadata ->getMaxDepth ();
44- if ($ depth > $ maxDepth ) {
45- $ resourceIdentifier = $ metadata ->getResourceIdentifier ();
46- return [
47- $ resourceIdentifier => $ array [$ resourceIdentifier ]
48- ];
49- }
41+ if ($ metadata ->hasReachedMaxDepth ($ depth )) {
42+ return $ array ;
5043 }
5144
5245 // Extract nested resources if present in metadata map
Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ public function createResource(
4747 $ routeParams [$ routeIdentifier ] = $ data [$ resourceIdentifier ];
4848 }
4949
50- $ maxDepth = $ metadata ->getMaxDepth ();
51- if ($ depth > $ maxDepth ) {
50+ if ($ metadata ->hasReachedMaxDepth ($ depth )) {
5251 $ data = [];
5352 }
5453
You can’t perform that action at this time.
0 commit comments