This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree 5 files changed +34
-14
lines changed
5 files changed +34
-14
lines changed Original file line number Diff line number Diff line change 9
9
10
10
use Zend \Expressive \Hal \LinkCollection ;
11
11
12
- abstract class AbstractMetadata
12
+ abstract class AbstractMetadata implements MetadataInterface
13
13
{
14
14
use LinkCollection;
15
15
@@ -22,4 +22,9 @@ public function getClass() : string
22
22
{
23
23
return $ this ->class ;
24
24
}
25
+
26
+ public function hasReachedMaxDepth (int $ currentDepth ): bool
27
+ {
28
+ return false ;
29
+ }
25
30
}
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
67
67
$ this ->routeParams = $ routeParams ;
68
68
}
69
69
70
- public function getMaxDepth ( ): int
70
+ public function hasReachedMaxDepth ( int $ currentDepth ): bool
71
71
{
72
- return $ this ->maxDepth ;
72
+ return $ currentDepth > $ this ->maxDepth ;
73
73
}
74
74
}
Original file line number Diff line number Diff line change 10
10
use Psr \Http \Message \ServerRequestInterface ;
11
11
use Zend \Expressive \Hal \Metadata \AbstractCollectionMetadata ;
12
12
use Zend \Expressive \Hal \Metadata \AbstractMetadata ;
13
- use Zend \Expressive \Hal \Metadata \RouteBasedResourceMetadata ;
14
13
use Zend \Expressive \Hal \ResourceGenerator ;
15
14
use Zend \Hydrator \ExtractionInterface ;
16
15
@@ -39,14 +38,8 @@ private function extractInstance(
39
38
40
39
$ array = $ extractor ->extract ($ instance );
41
40
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 ;
50
43
}
51
44
52
45
// 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(
47
47
$ routeParams [$ routeIdentifier ] = $ data [$ resourceIdentifier ];
48
48
}
49
49
50
- $ maxDepth = $ metadata ->getMaxDepth ();
51
- if ($ depth > $ maxDepth ) {
50
+ if ($ metadata ->hasReachedMaxDepth ($ depth )) {
52
51
$ data = [];
53
52
}
54
53
You can’t perform that action at this time.
0 commit comments