You are here

protected function RouteCondition::evaluateRouteWildcards in Route Condition 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Condition/RouteCondition.php \Drupal\route_condition\Plugin\Condition\RouteCondition::evaluateRouteWildcards()

Evaluate wildcards in route patterns.

Parameters

string $route_pattern: The route to evaluate for wildcards.

string $current_route_name: The current request route name.

Return value

bool Indication whether the provided route pattern matches the current route.

1 call to RouteCondition::evaluateRouteWildcards()
RouteCondition::evaluate in src/Plugin/Condition/RouteCondition.php
Evaluates the condition and returns TRUE or FALSE accordingly.

File

src/Plugin/Condition/RouteCondition.php, line 143

Class

RouteCondition
Provides a 'Route' condition.

Namespace

Drupal\route_condition\Plugin\Condition

Code

protected function evaluateRouteWildcards($route_pattern, $current_route_name) {
  if (strpos($route_pattern, '*') === FALSE) {
    return FALSE;
  }
  $escaped_route_pattern = str_replace('.', '\\.', $route_pattern);
  $route_pattern_wildcards = str_replace('*', '.*', $escaped_route_pattern);
  $regex = "{^{$route_pattern_wildcards}\$}";
  return (bool) preg_match($regex, $current_route_name);
}