You are here

class RouteAttributes in Page Manager 8.4

Same name and namespace in other branches
  1. 8 src/Routing/RouteAttributes.php \Drupal\page_manager\Routing\RouteAttributes

Provides utilities for interacting with route attributes.

@todo Consider moving to CTools.

Hierarchy

Expanded class hierarchy of RouteAttributes

1 file declares its use of RouteAttributes
RouteAttributesTest.php in tests/src/Unit/RouteAttributesTest.php

File

src/Routing/RouteAttributes.php, line 13

Namespace

Drupal\page_manager\Routing
View source
class RouteAttributes {

  /**
   * Extracts all of the raw attributes from a path for a given route.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route object.
   * @param string $name
   *   The route name.
   * @param string $path
   *   A path.
   *
   * @return array
   *   An array of raw attributes for this path and route.
   */
  public static function extractRawAttributes(Route $route, $name, $path) {

    // See \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection().
    preg_match($route
      ->compile()
      ->getRegex(), $path, $matches);

    // See \Symfony\Component\Routing\Matcher\UrlMatcher::mergeDefaults().
    $attributes = $route
      ->getDefaults();
    foreach ($matches as $key => $value) {
      if (!is_int($key)) {
        $attributes[$key] = $value;
      }
    }

    // See \Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher::getAttributes().
    $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
    $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
    return $attributes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteAttributes::extractRawAttributes public static function Extracts all of the raw attributes from a path for a given route.