@@ -57,18 +57,23 @@ public function __construct(array $options)
5757 public function filter (string $ path , $ data )
5858 {
5959 if (!isset ($ this ->options [$ path ])) {
60- // TODO: #19 find inclusive path
61- // $path = $this->findInclusivePaths($path, $this->options);
60+ $ path = $ this ->findInclusivePaths ($ path , $ this ->options );
6261
63- return $ data ;
62+ if (empty ($ path )) {
63+ return $ data ;
64+ }
6465 }
6566
6667 $ filters = $ this ->options [$ path ];
6768
6869 if (is_array ($ data )) {
69- return array_filter ($ data , function ($ item ) use ($ filters ) {
70- return $ this ->filterValue ($ item , $ filters );
70+ array_walk_recursive ($ data , function (&$ item , $ key ) use ($ filters , $ path ) {
71+ if (!is_array ($ item ) && substr ($ path , strrpos ($ path , '/ ' ) + 1 ) === $ key ) {
72+ $ item = $ this ->filterValue ($ item , $ filters );
73+ }
7174 });
75+
76+ return $ data ;
7277 }
7378
7479 return $ this ->filterValue ($ data , $ filters );
@@ -84,11 +89,11 @@ public function filter(string $path, $data)
8489 */
8590 private function filterValue ($ value , $ filters )
8691 {
87- $ filterType = $ filters ['type ' ] ?? 'string ' ;
88- $ filterArgs = $ filters ['args ' ] ?? [];
92+ $ isFiltered = false ;
93+ $ filterType = $ filters ['type ' ] ?? 'string ' ;
94+ $ filterArgs = $ filters ['args ' ] ?? [];
8995 $ filterCallback = $ filters ['callback ' ] ?? null ;
90-
91- $ value = $ this ->castType ($ value , $ filterType );
96+ $ value = $ this ->castType ($ value , $ filterType );
9297
9398 if (is_callable ($ filterCallback ) && $ filterCallback instanceof Closure) {
9499 $ args = [$ value ];
@@ -99,9 +104,9 @@ private function filterValue($value, $filters)
99104 $ args [] = $ filterArgs ;
100105 }
101106
102- return call_user_func_array ($ filterCallback , $ args );
107+ $ isFiltered = ! call_user_func_array ($ filterCallback , $ args );
103108 }
104109
105- return $ value ;
110+ return $ isFiltered ? false : $ value ;
106111 }
107112}
0 commit comments