@@ -156,7 +156,9 @@ public function setResponse(ResponseInterface $response)
156156 * Runs through all of the filters for the specified
157157 * uri and position.
158158 *
159- * @return mixed|RequestInterface|ResponseInterface
159+ * @param string $uri URI path relative to baseURL
160+ *
161+ * @return RequestInterface|ResponseInterface|string|null
160162 *
161163 * @throws FilterException
162164 */
@@ -221,6 +223,8 @@ public function run(string $uri, string $position = 'before')
221223 * run through both a before and after and don't want to double
222224 * process the rows.
223225 *
226+ * @param string|null $uri URI path relative to baseURL (all lowercase)
227+ *
224228 * @return Filters
225229 */
226230 public function initialize (?string $ uri = null )
@@ -391,7 +395,7 @@ public function getArguments(?string $key = null)
391395 /**
392396 * Add any applicable (not excluded) global filter settings to the mix.
393397 *
394- * @param string $uri
398+ * @param string|null $uri URI path relative to baseURL (all lowercase)
395399 *
396400 * @return void
397401 */
@@ -416,7 +420,7 @@ protected function processGlobals(?string $uri = null)
416420 if (isset ($ rules ['except ' ])) {
417421 // grab the exclusion rules
418422 $ check = $ rules ['except ' ];
419- if ($ this ->pathApplies ($ uri , $ check )) {
423+ if ($ this ->checkExcept ($ uri , $ check )) {
420424 $ keep = false ;
421425 }
422426 }
@@ -454,7 +458,7 @@ protected function processMethods()
454458 /**
455459 * Add any applicable configured filters to the mix.
456460 *
457- * @param string $uri
461+ * @param string|null $uri URI path relative to baseURL (all lowercase)
458462 *
459463 * @return void
460464 */
@@ -536,12 +540,47 @@ private function pathApplies(string $uri, $paths)
536540 $ paths = [$ paths ];
537541 }
538542
539- // treat each paths as pseudo-regex
543+ return $ this ->checkPseudoRegex ($ uri , $ paths );
544+ }
545+
546+ /**
547+ * Check except paths
548+ *
549+ * @param string $uri URI path relative to baseURL (all lowercase)
550+ * @param array|string $paths The except path patterns
551+ *
552+ * @return bool True if the URI matches except paths.
553+ */
554+ private function checkExcept (string $ uri , $ paths ): bool
555+ {
556+ // empty array does not match anything
557+ if ($ paths === []) {
558+ return false ;
559+ }
560+
561+ // make sure the paths are iterable
562+ if (is_string ($ paths )) {
563+ $ paths = [$ paths ];
564+ }
565+
566+ return $ this ->checkPseudoRegex ($ uri , $ paths );
567+ }
568+
569+ /**
570+ * Check the URI path as pseudo-regex
571+ *
572+ * @param string $uri URI path relative to baseURL (all lowercase)
573+ * @param array $paths The except path patterns
574+ */
575+ private function checkPseudoRegex (string $ uri , array $ paths ): bool
576+ {
577+ // treat each path as pseudo-regex
540578 foreach ($ paths as $ path ) {
541579 // need to escape path separators
542580 $ path = str_replace ('/ ' , '\/ ' , trim ($ path , '/ ' ));
543581 // need to make pseudo wildcard real
544582 $ path = strtolower (str_replace ('* ' , '.* ' , $ path ));
583+
545584 // Does this rule apply here?
546585 if (preg_match ('#^ ' . $ path . '$# ' , $ uri , $ match ) === 1 ) {
547586 return true ;
0 commit comments