@@ -12,7 +12,15 @@ class Includes
12
12
13
13
private static array $ stack = [];
14
14
15
- public static function through (string $ type , callable $ callable )
15
+ /**
16
+ * Defined current resource-type/relation through callback
17
+ *
18
+ * @param string $type
19
+ * @param callable $callable
20
+ *
21
+ * @return mixed
22
+ */
23
+ public static function through (string $ type , callable $ callable ): mixed
16
24
{
17
25
try {
18
26
self ::$ stack [] = $ type ;
@@ -23,13 +31,41 @@ public static function through(string $type, callable $callable)
23
31
}
24
32
}
25
33
34
+ /**
35
+ * Return remaining includes for current resource
36
+ *
37
+ * @param \Illuminate\Http\Request $request
38
+ *
39
+ * @return array
40
+ */
26
41
public static function get (Request $ request ): array
27
42
{
28
- return array_keys (Arr::get (
29
- self ::parse ($ request ->input ('include ' , '' )),
30
- implode ('. ' , self ::$ stack ) ?: null ,
31
- []
32
- ));
43
+ return array_keys (self ::currentStack ($ request ));
44
+ }
45
+
46
+ /**
47
+ * Return if a resource-type/relation is included
48
+ *
49
+ * @param \Illuminate\Http\Request $request
50
+ * @param string $type
51
+ *
52
+ * @return bool
53
+ */
54
+ public static function include (Request $ request , string $ type ): bool
55
+ {
56
+ return in_array ($ type , self ::get ($ request ), true );
57
+ }
58
+
59
+ /**
60
+ * Return remaining includes
61
+ *
62
+ * @param \Illuminate\Http\Request $request
63
+ *
64
+ * @return array
65
+ */
66
+ public static function includes (Request $ request ): array
67
+ {
68
+ return array_keys (Arr::dot (self ::currentStack ($ request )));
33
69
}
34
70
35
71
public static function parse (string $ include ): array
@@ -39,8 +75,12 @@ public static function parse(string $include): array
39
75
);
40
76
}
41
77
42
- public static function include (Request $ request, string $ type ): bool
78
+ private static function currentStack (Request $ request ): array
43
79
{
44
- return in_array ($ type , self ::get ($ request ), true );
80
+ return Arr::get (
81
+ self ::parse ($ request ->input ('include ' , '' )),
82
+ implode ('. ' , self ::$ stack ) ?: null ,
83
+ []
84
+ );
45
85
}
46
86
}
0 commit comments