_hasParams

Checks if a param exists in a route and if this param matches the constraints defined in that route

@param string    $route
@param array     $params
@param array     $constraints

@return bool True if the params match the constraints
760974
private function _hasParams($route, $params, $constraints)
    {
        foreach ($params as $key => $value)
        {
            if ( strpos(preg_replace('/\s+/', '', $route), '{' . $key . '}') === false ||
                (array_key_exists($key, $constraints) &&
                    preg_match('!' . preg_replace('/\s+/', '', $constraints[$key]) . '!', $value) == 0)
            )
                return false;
        }

        return true;
    }
407221
public function match($route, $method = 'GET', $options = [])
    {
        $this->method = $method;
        $this->options = $options;
        $this->count = 0;

        // Init some data
        $this->buildRouteMaps()
            ->buildTree();

        // Match
        $segments = explode('/', RouteHelper::sanitize($route));

        $routeItem = $this->matchSegment($segments, $this->tree);

        if (!$routeItem) {
            return false;
        }

        $routeItem->setVariables(array_merge($routeItem->getVariables(), $this->vars));

        return $routeItem;
    }
1323918
public static function fromRoute(Route $route, array $params = []): self
    {
        $result = new self();
        $result->success = true;
        $result->route = $route;
        $result->matchedParams = $params;

        return $result;
    }
704064
protected function parse($pattern, $route, $params)
    {
        $pattern = ltrim($pattern, '/');
        if (preg_match_all(self::REGEX, $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
            $regex = '~^';
            $variables = [];
            $offset = 0;
            $i = 1;
            foreach ($matches as $match) {
                if ($match[0][1] > $offset) {
                    $regex .= preg_quote(substr($pattern, $offset, $match[0][1] - $offset), '~');
                }
                $variables['d' . $i] = $match[1][0];
                $_regex = isset($match[2][0]) ? $match[2][0] : self::DEFAULT_REGEX;
                $regex .= "(?P<d{$i}>$_regex)";
                $offset = $match[0][1] + strlen($match[0][0]);
                $i++;
            }

            if ($offset != strlen($pattern)) {
                $regex .= preg_quote(substr($pattern, $offset), '~');
            }
            $regex .= '$~';
            $this->_routes['var'][$regex] = [$route, $params, $variables];
        } else {
            $this->_routes['static'][$pattern] = [$route, $params];
        }
    }
1182515
public function execute($route, array $parameters = array(), \Exedra\Http\ServerRequest $request = null)
    {
        $route = $this->baseRoute($route);

        $request = $request ? : $this->request;

        return $this->app->execute($route, $parameters, $request);
    }
632130
public function add(Route $route, array $params = [])
    {
        $callback = $route->getCallable();
        if (empty($callback)) {
            return;
        }

        $this->routes[] = $route->getRoute();
        $paramNames = $route->getParamNames();
        foreach ($paramNames as $name) {
            if (isset($params[$name])) {
                $this->setParam($name, $params[$name]);
            }
        }

        if (is_array($callback)) {
            $this->callable = array_merge($this->callable, $callback);
        } elseif (!in_array($callback, $this->callable)) {
            $this->callable[] = $callback;
        }
    }
919430
def has_param(param):
    
    def has_param_closure(element):
        """
        Look for `param` in `element`.
        """
        if element.params.get(param, "").strip():
            return True

        return False

    return has_param_closure
590417
private function methodMatches(array $route)
    {
        $methods = explode('|', $route['method']);
        if (in_array($this->method, $methods)) {
            return true;
        }

        return false;
    }
23383
public function isRoute($routes)
    {
        $routes = is_array($routes) ? $routes : func_get_args();

        return call_user_func_array([$this->router, 'is'], $routes);
    }
1331569
function getRouteParams(route, params) {
  const routeParams = {}

  if (!route.path)
    return routeParams

  const paramNames = getParamNames(route.path)

  for (const p in params) {
    if (
      Object.prototype.hasOwnProperty.call(params, p) &&
      paramNames.indexOf(p) !== -1
    ) {
      routeParams[p] = params[p]
    }
  }

  return routeParams
}
692112
public function setRoute(string $route = null, array $params = []): ButtonInterface
    {
        if ($this->isVisibility()) {
            if ($route === null) {
                $url = '#';
            } else {
                $url = '#';
                if (app('router')->has($route)) {
                    $url = route($route, $params);
                } else {
                    $this->setVisible(false);
                }
            }
            $this->setUrl($url);
        }

        return $this;
    }
692971
public function toRoute($route = null, $params = array(), $query = array())
    {
        if(!$route)
            return $this->refresh();

        $url = $this->urlFactory->create($route, $params, $query);

        return $this->to($url);
    }
1264405
private function insertDefaultParameterValues(Route $route, array $missing, array $parameters)
    {
        $values = $route->getDefaultValues();
        foreach ($missing as $key => $pattern) {
            if (isset($values[$key])) {
                $parameters[$key] = $values[$key];
                unset($missing[$key]);
            }
        }
        if (!empty($missing)) {
            $params = join(', ', array_keys($missing));
            throw new \InvalidArgumentException("Parameters not set: {$params}");
        }

        return $parameters;
    }
761753
public function delete($route, $params = [])
    {
        $route = $this->parseRoute($route, $params);
        $request = Request::create($route, 'DELETE', Input::all());
        $response = Route::dispatch($request);

        return $response;
    }
724972
private function _setParamsToRoute($route, $params)
    {
        foreach ($params as $key => $value)
        {
            $route = preg_replace('/\{' . $key . '\}/', $value, $route);
        }

        return $route;
    }
895796
public function setRoute($route, array $params = array())
    {
        $this->route = $route;
        $this->routeParams = $params;

        return $this;
    }
1029126
protected function check(array $routes, $request)
	{
		return array_first($routes, function($key, $value) use ($request)
		{
			return $value->matches($request);
		});
	}