Example #1
0
 /**
  * Set before match callable for route.
  * Sometimes, routes must be matched if they meet specific conditions,
  * you can add arbitrary conditions to routes using the ‘beforeMatch’ callback,
  * if this function return false, the route will be treaded as non-matched
  *
  * @param Route $route
  * @param string|callable $config
  */
 protected function setBeforeMatch(Route $route, $config)
 {
     $obj = $this->getInstanceHelper($config);
     $isCallable = is_callable($obj);
     if (!$isCallable && !$obj instanceof BeforeMatchInterface) {
         $errMsg = sprintf('"%s" must be implemented "%s"', get_class($obj), BeforeMatchInterface::class);
         throw new Exception\RuntimeException($errMsg);
     }
     $beforeMatch = $isCallable ? $obj : [$obj, 'beforeMatch'];
     $route->beforeMatch($beforeMatch);
 }