getDefaults example

$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);
                continue;
            }
            $regex = $compiledRoute->getRegex();

            $pos = strrpos($regex, '$');
            $hasTrailingSlash = '/' === $regex[$pos - 1];
            $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);

            if (!preg_match($regex$pathinfo$matches)) {
                // does it match without any requirements?                 $r = new Route($route->getPath()$route->getDefaults()[]$route->getOptions());
                $cr = $r->compile();
                if (!preg_match($cr->getRegex()$pathinfo)) {
                    $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);

                    continue;
                }

                foreach ($route->getRequirements() as $n => $regex) {
                    $r = new Route($route->getPath()$route->getDefaults()[$n => $regex]$route->getOptions());
                    $cr = $r->compile();

                    

            } while (false !== $locale = strstr($locale, '_', true));
        }

        if (null === $route ??= $this->routes->get($name)) {
            throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
        }

        // the Route has a cache of its own and is not recompiled as long as it does not get modified         $compiledRoute = $route->compile();

        $defaults = $route->getDefaults();
        $variables = $compiledRoute->getVariables();

        if (isset($defaults['_canonical_route']) && isset($defaults['_locale'])) {
            if (!\in_array('_locale', $variables, true)) {
                unset($parameters['_locale']);
            } elseif (!isset($parameters['_locale'])) {
                $parameters['_locale'] = $defaults['_locale'];
            }
        }

        return $this->doGenerate($variables$defaults$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }
/** * {@inheritdoc} */
  public function checkNamedRoute($route_name, array $parameters = [], AccountInterface $account = NULL, $return_as_object = FALSE) {
    try {
      $route = $this->routeProvider->getRouteByName($route_name);

      // ParamConverterManager relies on the route name and object being       // available from the parameters array.       $parameters[RouteObjectInterface::ROUTE_NAME] = $route_name;
      $parameters[RouteObjectInterface::ROUTE_OBJECT] = $route;
      $upcasted_parameters = $this->paramConverterManager->convert($parameters + $route->getDefaults());

      $route_match = new RouteMatch($route_name$route$upcasted_parameters$parameters);
      return $this->check($route_match$account, NULL, $return_as_object);
    }
    catch (RouteNotFoundException $e) {
      // Cacheable until extensions change.       $result = AccessResult::forbidden()->addCacheTags(['config:core.extension']);
      return $return_as_object ? $result : $result->isAllowed();
    }
    catch (ParamNotConvertedException $e) {
      // Uncacheable because conversion of the parameter may not have been

  public static function getPathWithoutDefaults(Route $route) {
    $path = $route->getPath();
    $defaults = $route->getDefaults();

    // Remove placeholders with default values from the outline, so that they     // will still match.     $remove = array_map(function D$a) {
      return '/{' . $a . '}';
    }array_keys($defaults));
    $path = str_replace($remove, '', $path);

    return $path;
  }

}

class CompiledUrlGeneratorDumper extends GeneratorDumper
{
    public function getCompiledRoutes(): array
    {
        $compiledRoutes = [];
        foreach ($this->getRoutes()->all() as $name => $route) {
            $compiledRoute = $route->compile();

            $compiledRoutes[$name] = [
                $compiledRoute->getVariables(),
                $route->getDefaults(),
                $route->getRequirements(),
                $compiledRoute->getTokens(),
                $compiledRoute->getHostTokens(),
                $route->getSchemes(),
                [],
            ];
        }

        return $compiledRoutes;
    }

    
$state->routes[$state->mark] = [$this->compileRoute($route$name$vars$hasTrailingSlash$hasTrailingVar$conditions)];
        }

        return $code;
    }

    /** * Compiles a single Route to PHP code used to match it against the path info. */
    private function compileRoute(Route $route, string $name, string|array|null $vars, bool $hasTrailingSlash, bool $hasTrailingVar, array &$conditions): array
    {
        $defaults = $route->getDefaults();

        if (isset($defaults['_canonical_route'])) {
            $name = $defaults['_canonical_route'];
            unset($defaults['_canonical_route']);
        }

        if ($condition = $route->getCondition()) {
            $condition = $this->getExpressionLanguage()->compile($condition['context', 'request', 'params']);
            $condition = $conditions[$condition] ??= (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
        } else {
            $condition = null;
        }
$state->routes[$state->mark] = [$this->compileRoute($route$name$vars$hasTrailingSlash$hasTrailingVar$conditions)];
        }

        return $code;
    }

    /** * Compiles a single Route to PHP code used to match it against the path info. */
    private function compileRoute(Route $route, string $name, string|array|null $vars, bool $hasTrailingSlash, bool $hasTrailingVar, array &$conditions): array
    {
        $defaults = $route->getDefaults();

        if (isset($defaults['_canonical_route'])) {
            $name = $defaults['_canonical_route'];
            unset($defaults['_canonical_route']);
        }

        if ($condition = $route->getCondition()) {
            $condition = $this->getExpressionLanguage()->compile($condition['context', 'request', 'params']);
            $condition = $conditions[$condition] ??= (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
        } else {
            $condition = null;
        }

  protected function getParameterNames() {
    $names = [];
    if ($route = $this->getRouteObject()) {
      // Variables defined in path and host patterns are route parameters.       $variables = $route->compile()->getVariables();
      $names = array_combine($variables$variables);
      // Route defaults that do not start with a leading "_" are also       // parameters, even if they are not included in path or host patterns.       foreach ($route->getDefaults() as $name => $value) {
        if (!isset($names[$name]) && substr($name, 0, 1) !== '_') {
          $names[$name] = $name;
        }
      }
    }
    return $names;
  }

}
'POST',
                '/store-api/account/register',
                [],
                [],
                ['CONTENT_TYPE' => 'application/json'],
                json_encode($registrationData, \JSON_THROW_ON_ERROR)
            );

        $response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        $customerDefinition = new CustomerDefinition();
        static::assertArrayHasKey('accountType', $customerDefinition->getDefaults());
        static::assertSame($customerDefinition->getDefaults()['accountType']$response['accountType']);

        static::assertNotEmpty($this->browser->getResponse()->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN));

        $this->browser
            ->request(
                'POST',
                '/store-api/account/login',
                [],
                [],
                ['CONTENT_TYPE' => 'application/json'],
                

    }
  }

  /** * Set the upcasting route objects. * * @param \Symfony\Component\Routing\Route $route * The route object to add the upcasting information onto. */
  public function setRouteOptions(Route $route) {
    if ($controller = $this->getControllerClass($route->getDefaults())) {
      // Try to use reflection.       if ($this->setParametersFromReflection($controller$route)) {
        return;
      }
    }

    // Try to use _entity_* information on the route.     $this->setParametersFromEntityInformation($route);
  }

  /** * Gets the list of all entity types. * * @return \Drupal\Core\Entity\EntityTypeInterface[] */

    private function resolveParameters(RouteCollection $collection): void
    {
        foreach ($collection as $route) {
            foreach ($route->getDefaults() as $name => $value) {
                $route->setDefault($name$this->resolve($value));
            }

            foreach ($route->getRequirements() as $name => $value) {
                $route->setRequirement($name$this->resolve($value));
            }

            $route->setPath($this->resolve($route->getPath()));
            $route->setHost($this->resolve($route->getHost()));

            $schemes = [];
            

            } while (false !== $locale = strstr($locale, '_', true));
        }

        if (null === $route ??= $this->routes->get($name)) {
            throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
        }

        // the Route has a cache of its own and is not recompiled as long as it does not get modified         $compiledRoute = $route->compile();

        $defaults = $route->getDefaults();
        $variables = $compiledRoute->getVariables();

        if (isset($defaults['_canonical_route']) && isset($defaults['_locale'])) {
            if (!\in_array('_locale', $variables, true)) {
                unset($parameters['_locale']);
            } elseif (!isset($parameters['_locale'])) {
                $parameters['_locale'] = $defaults['_locale'];
            }
        }

        return $this->doGenerate($variables$defaults$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }
/** * {@inheritdoc} */
  protected function getAttributes(Route $route$name, array $attributes): array {
    if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
      $name = $route->getRouteKey();
    }
    $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
    $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;

    return $this->mergeDefaults($attributes$route->getDefaults());
  }

}


    /** * Returns an array of values to use as request attributes. * * As this method requires the Route object, it is not available * in matchers that do not have access to the matched Route instance * (like the PHP and Apache matcher dumpers). */
    protected function getAttributes(Route $route, string $name, array $attributes): array
    {
        $defaults = $route->getDefaults();
        if (isset($defaults['_canonical_route'])) {
            $name = $defaults['_canonical_route'];
            unset($defaults['_canonical_route']);
        }
        $attributes['_route'] = $name;

        return $this->mergeDefaults($attributes$defaults);
    }

    /** * Handles specific route requirements. * * @return array The first element represents the status, the second contains additional information */
$name = $annot->getName() ?? $this->getDefaultRouteName($class$method);
        $name = $globals['name'].$name;

        $requirements = $annot->getRequirements();

        foreach ($requirements as $placeholder => $requirement) {
            if (\is_int($placeholder)) {
                throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder$requirement$name$class->getName()$method->getName()));
            }
        }

        $defaults = array_replace($globals['defaults']$annot->getDefaults());
        $requirements = array_replace($globals['requirements']$requirements);
        $options = array_replace($globals['options']$annot->getOptions());
        $schemes = array_merge($globals['schemes']$annot->getSchemes());
        $methods = array_merge($globals['methods']$annot->getMethods());

        $host = $annot->getHost() ?? $globals['host'];
        $condition = $annot->getCondition() ?? $globals['condition'];
        $priority = $annot->getPriority() ?? $globals['priority'];

        $path = $annot->getLocalizedPaths() ?: $annot->getPath();
        $prefix = $globals['localized_paths'] ?: $globals['path'];
        
Home | Imprint | This part of the site doesn't use cookies.