@@ -574,14 +574,14 @@ public function addFilter(string $class, ?string $alias = null, string $position
574
574
* after the filter name, followed by a comma-separated list of arguments that
575
575
* are passed to the filter when executed.
576
576
*
577
- * @param string $name filter_name or filter_name:arguments like 'role:admin,manager'
577
+ * @param string $filter filter_name or filter_name:arguments like 'role:admin,manager'
578
578
* or filter classname.
579
579
* @phpstan-param 'before'|'after' $position
580
580
*/
581
- private function enableFilter (string $ name , string $ position = 'before ' ): void
581
+ private function enableFilter (string $ filter , string $ position = 'before ' ): void
582
582
{
583
583
// Normalize the arguments.
584
- [$ alias , $ arguments ] = $ this ->getCleanName ($ name );
584
+ [$ alias , $ arguments ] = $ this ->getCleanName ($ filter );
585
585
$ filter = ($ arguments === []) ? $ alias : $ alias . ': ' . implode (', ' , $ arguments );
586
586
587
587
if (class_exists ($ alias )) {
@@ -602,24 +602,26 @@ private function enableFilter(string $name, string $position = 'before'): void
602
602
/**
603
603
* Get clean name and arguments
604
604
*
605
- * @param string $name filter_name or filter_name:arguments like 'role:admin,manager'
605
+ * @param string $filter filter_name or filter_name:arguments like 'role:admin,manager'
606
606
*
607
607
* @return array{0: string, 1: list<string>} [name, arguments]
608
608
*/
609
- private function getCleanName (string $ name ): array
609
+ private function getCleanName (string $ filter ): array
610
610
{
611
611
$ arguments = [];
612
612
613
- if (str_contains ($ name , ': ' )) {
614
- [$ name , $ arguments ] = explode (': ' , $ name );
615
-
616
- $ arguments = explode (', ' , $ arguments );
617
- array_walk ($ arguments , static function (&$ item ) {
618
- $ item = trim ($ item );
619
- });
613
+ if (! str_contains ($ filter , ': ' )) {
614
+ return [$ filter , $ arguments ];
620
615
}
621
616
622
- return [$ name , $ arguments ];
617
+ [$ alias , $ arguments ] = explode (': ' , $ filter );
618
+
619
+ $ arguments = explode (', ' , $ arguments );
620
+ array_walk ($ arguments , static function (&$ item ) {
621
+ $ item = trim ($ item );
622
+ });
623
+
624
+ return [$ alias , $ arguments ];
623
625
}
624
626
625
627
/**
@@ -629,13 +631,13 @@ private function getCleanName(string $name): array
629
631
* after the filter name, followed by a comma-separated list of arguments that
630
632
* are passed to the filter when executed.
631
633
*
632
- * @params array <string> $names filter_name or filter_name:arguments like 'role:admin,manager'
634
+ * @param list <string> $filters filter_name or filter_name:arguments like 'role:admin,manager'
633
635
*
634
636
* @return Filters
635
637
*/
636
- public function enableFilters (array $ names , string $ when = 'before ' )
638
+ public function enableFilters (array $ filters , string $ when = 'before ' )
637
639
{
638
- foreach ($ names as $ filter ) {
640
+ foreach ($ filters as $ filter ) {
639
641
$ this ->enableFilter ($ filter , $ when );
640
642
}
641
643
@@ -777,21 +779,25 @@ protected function processFilters(?string $uri = null)
777
779
// Add any filters that apply to this URI
778
780
$ filters = [];
779
781
780
- foreach ($ this ->config ->filters as $ alias => $ settings ) {
782
+ foreach ($ this ->config ->filters as $ filter => $ settings ) {
783
+ // Normalize the arguments.
784
+ [$ alias , $ arguments ] = $ this ->getCleanName ($ filter );
785
+ $ filter = ($ arguments === []) ? $ alias : $ alias . ': ' . implode (', ' , $ arguments );
786
+
781
787
// Look for inclusion rules
782
788
if (isset ($ settings ['before ' ])) {
783
789
$ path = $ settings ['before ' ];
784
790
785
791
if ($ this ->pathApplies ($ uri , $ path )) {
786
- $ filters ['before ' ][] = $ alias ;
792
+ $ filters ['before ' ][] = $ filter ;
787
793
}
788
794
}
789
795
790
796
if (isset ($ settings ['after ' ])) {
791
797
$ path = $ settings ['after ' ];
792
798
793
799
if ($ this ->pathApplies ($ uri , $ path )) {
794
- $ filters ['after ' ][] = $ alias ;
800
+ $ filters ['after ' ][] = $ filter ;
795
801
}
796
802
}
797
803
}
0 commit comments