Content-Length: 264214 | pFad | http://github.com/symfony/symfony/issues/60367

A3 Allow defining non-localized routes explicitly when using auto-prefixing · Issue #60367 · symfony/symfony · GitHub
Skip to content

Allow defining non-localized routes explicitly when using auto-prefixing #60367

@speller

Description

@speller

Description

Symfony allows configuring the auto-prefixing of all routes with a list of locales. But sometimes, while the vast majority of URLs should be localized, some of them should be neutral and avoid auto-prefixing.

The suggestion is to allow defining explicit exclusion of routes from auto-prefixing with the new Route attribute locale value: false:

--- a/Loader/Configurator/Traits/PrefixTrait.php
+++ b/Loader/Configurator/Traits/PrefixTrait.php
@@ -39,6 +39,9 @@
                         $localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
                         $routes->add($name.'.'.$locale, $localizedRoute, $priority);
                     }
+                } elseif (false === $locale) {
+                    // Explicitly non-prefixed non-localized route.
+                    $route->setDefault('_locale', null);
                 } elseif (!isset($prefix[$locale])) {
                     throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
                 } else {
--- a/Attribute/Route.php
+++ b/Attribute/Route.php
@@ -51,7 +51,7 @@
         array|string $schemes = [],
         private ?string $condition = null,
         private ?int $priority = null,
-        ?string $locale = null,
+        string|false|null $locale = null,
         ?string $format = null,
         ?bool $utf8 = null,
         ?bool $stateless = null,

With this patch, I'm able to configure routes like this:

    #[Route('/.well-known/jwks.json', name: 'public_jwks', methods: ['GET'], locale: false, stateless: true)]

This allows the route to be excluded from auto-prefixing and remain as-is.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/symfony/symfony/issues/60367

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy