Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented May 22, 2025

Q A
License MIT
Doc issue/PR symfony/symfony-docs#...

Like database connection, domains are mostly managed OPS team and not by developers. To skip that the developer team need to keep in mind to add a env variable for the default_uri it would be nice if its out of the box a env variable exists – which can always be set by the ops team without have a developer to change the symfony app before.

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) May 22, 2025 11:59
@github-actions
Copy link

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1416/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1416/index.json
  2. Install the package(s) related to this recipe:

    composer req symfony/flex
    composer req 'symfony/routing:^7.0'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

symfony/routing

3.3 vs 4.0
diff --git a/symfony/routing/3.3/config/routes.yaml b/symfony/routing/4.0/config/routes.yaml
index 59d1945..c3283aa 100644
--- a/symfony/routing/3.3/config/routes.yaml
+++ b/symfony/routing/4.0/config/routes.yaml
@@ -1,6 +1,3 @@
-# This file is the entry point to configure your own HTTP routes.
-# Files in the routes/ subdirectory configure the routes for your dependencies.
-
 #index:
 #    path: /
-#    defaults: { _controller: 'App\Controller\DefaultController::index' }
+#    controller: App\Controller\DefaultController::index
4.0 vs 4.2
diff --git a/symfony/routing/4.2/config/packages/routing.yaml b/symfony/routing/4.2/config/packages/routing.yaml
new file mode 100644
index 0000000..7e97762
--- /dev/null
+++ b/symfony/routing/4.2/config/packages/routing.yaml
@@ -0,0 +1,3 @@
+framework:
+    router:
+        utf8: true
4.2 vs 5.1
diff --git a/symfony/routing/4.2/config/packages/routing.yaml b/symfony/routing/5.1/config/packages/routing.yaml
index 7e97762..b45c1ce 100644
--- a/symfony/routing/4.2/config/packages/routing.yaml
+++ b/symfony/routing/5.1/config/packages/routing.yaml
@@ -1,3 +1,7 @@
 framework:
     router:
         utf8: true
+
+        # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
+        # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
+        #default_uri: http://localhost
5.1 vs 5.3
diff --git a/symfony/routing/5.1/config/packages/prod/routing.yaml b/symfony/routing/5.1/config/packages/prod/routing.yaml
deleted file mode 100644
index b3e6a0a..0000000
--- a/symfony/routing/5.1/config/packages/prod/routing.yaml
+++ /dev/null
@@ -1,3 +0,0 @@
-framework:
-    router:
-        strict_requirements: null
diff --git a/symfony/routing/5.1/config/packages/routing.yaml b/symfony/routing/5.3/config/packages/routing.yaml
index b45c1ce..4b766ce 100644
--- a/symfony/routing/5.1/config/packages/routing.yaml
+++ b/symfony/routing/5.3/config/packages/routing.yaml
@@ -5,3 +5,8 @@ framework:
         # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
         # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
         #default_uri: http://localhost
+
+when@prod:
+    framework:
+        router:
+            strict_requirements: null
diff --git a/symfony/routing/5.1/manifest.json b/symfony/routing/5.3/manifest.json
index c0c66b6..a3f340e 100644
--- a/symfony/routing/5.1/manifest.json
+++ b/symfony/routing/5.3/manifest.json
@@ -2,5 +2,8 @@
     "copy-from-recipe": {
         "config/": "%CONFIG_DIR%/"
     },
-    "aliases": ["router"]
+    "aliases": ["router"],
+    "conflict": {
+        "symfony/framework-bundle": "<5.3"
+    }
 }
5.3 vs 6.0
diff --git a/symfony/routing/5.3/config/routes.yaml b/symfony/routing/6.0/config/routes.yaml
index c3283aa..5b102f6 100644
--- a/symfony/routing/5.3/config/routes.yaml
+++ b/symfony/routing/6.0/config/routes.yaml
@@ -1,3 +1,7 @@
-#index:
-#    path: /
-#    controller: App\Controller\DefaultController::index
+controllers:
+    resource: ../src/Controller/
+    type: annotation
+
+kernel:
+    resource: ../src/Kernel.php
+    type: annotation
6.0 vs 6.1
diff --git a/symfony/routing/6.0/config/routes.yaml b/symfony/routing/6.1/config/routes.yaml
index 5b102f6..9286e81 100644
--- a/symfony/routing/6.0/config/routes.yaml
+++ b/symfony/routing/6.1/config/routes.yaml
@@ -1,7 +1,3 @@
 controllers:
     resource: ../src/Controller/
-    type: annotation
-
-kernel:
-    resource: ../src/Kernel.php
-    type: annotation
+    type: attribute
6.1 vs 6.2
diff --git a/symfony/routing/6.1/config/routes.yaml b/symfony/routing/6.2/config/routes.yaml
index 9286e81..41ef814 100644
--- a/symfony/routing/6.1/config/routes.yaml
+++ b/symfony/routing/6.2/config/routes.yaml
@@ -1,3 +1,5 @@
 controllers:
-    resource: ../src/Controller/
+    resource:
+        path: ../src/Controller/
+        namespace: App\Controller
     type: attribute
diff --git a/symfony/routing/6.1/manifest.json b/symfony/routing/6.2/manifest.json
index a3f340e..db10260 100644
--- a/symfony/routing/6.1/manifest.json
+++ b/symfony/routing/6.2/manifest.json
@@ -4,6 +4,6 @@
     },
     "aliases": ["router"],
     "conflict": {
-        "symfony/framework-bundle": "<5.3"
+        "symfony/framework-bundle": "<6.2"
     }
 }
6.2 vs 7.0
diff --git a/symfony/routing/6.2/config/packages/routing.yaml b/symfony/routing/7.0/config/packages/routing.yaml
index 4b766ce..0f34f87 100644
--- a/symfony/routing/6.2/config/packages/routing.yaml
+++ b/symfony/routing/7.0/config/packages/routing.yaml
@@ -1,10 +1,8 @@
 framework:
     router:
-        utf8: true
-
         # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
         # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
-        #default_uri: http://localhost
+        default_uri: '%env(DEFAULT_URI)%'
 
 when@prod:
     framework:
diff --git a/symfony/routing/6.2/manifest.json b/symfony/routing/7.0/manifest.json
index db10260..7dcd4ae 100644
--- a/symfony/routing/6.2/manifest.json
+++ b/symfony/routing/7.0/manifest.json
@@ -4,6 +4,11 @@
     },
     "aliases": ["router"],
     "conflict": {
-        "symfony/framework-bundle": "<6.2"
+        "symfony/framework-bundle": "<7.0"
+    },
+    "env": {
+        "#1": "Configure how to generate URLs in non-HTTP contexts, such as CLI commands.",
+        "#2": "See https://symfony.com/doc/current/routing.html#generating-urls-in-commands",
+        "DEFAULT_URI": "http://localhost"
     }
 }

@OskarStark OskarStark changed the title Add env variable for router default_uri configuration Add env variable for router.default_uri configuration option Jun 2, 2025
@alexander-schranz
Copy link
Contributor Author

@fabpot as we have released: https://github.com/symfony-cli/symfony-cli/releases/tag/v5.13.0 can we merge this?

@fabpot fabpot disabled auto-merge September 22, 2025 05:34
@fabpot fabpot merged commit fc12199 into symfony:main Sep 22, 2025
1 of 2 checks passed
@alexander-schranz alexander-schranz deleted the feature/default-uri-env branch September 22, 2025 05:35
@melroy89
Copy link

melroy89 commented Sep 22, 2025

@alexander-schranz After this recipe upgrade I get an error:

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!  
!!   // Clearing the cache for the prod environment with debug false                
!!  
!!  
!!  In EnvVarProcessor.php line 221:
!!                                                    
!!    Environment variable not found: "DEFAULT_URI".  
!!                                                    
!!  
!!  cache:clear [--no-warmup] [--no-optional-warmers]
!!  
!!  
Script @auto-scripts was called via post-install-cmd

While there was no recipe introducing any new en var called DEFAULT_URI..

So that means I now need to add a new environment variable called DEFAULT_URI to the .env file right? If so, what is a good default? Or what do I wrong?

Not only that.. I'm missing documentation about this change at: https://symfony.com/doc/current/routing.html

@alexander-schranz
Copy link
Contributor Author

@melroy89 you need just run compsoser recipes:update that adds the new variable to your .env file. I did that in @sulu and it did it without any problem: sulu/skeleton#302

@melroy89
Copy link

melroy89 commented Sep 22, 2025

Thanks for your reply.. The composer recipes:update command did NOT add this DEFAULT_URI to my .env file to be fully honest.

Also in our case, with our Mbin project, the .env file is actually added to .gitignore.. But thanks anyways. I will add this new env var to our .env.test and .env.dev and .env.example files.

And apparently http://localhost is the default value here.

@alexander-schranz
Copy link
Contributor Author

That might be the problem the .env should not be part of .gitignore only .env.local and .env.*.local files in Symfony projects.

@melroy89
Copy link

That might be the problem the .env should not be part of .gitignore only .env.local and .env.*.local files in Symfony projects.

yeah I blame our project setup for this mistake indeed. Sorry to bother you 👍🏽 .

@fmonts
Copy link

fmonts commented Oct 15, 2025

Shouldn't it contain a trailing slash?

the docs say:

framework:
    router:
        # ...
        default_uri: 'https://example.org/my/path/'

But the recipe has http://localhost, this makes it unclear if we should use https://mysite.com or https://mysite.com/
IMHO a trailing slash should be added to the recipe as well, to look like a proper url and avoid any confusion.

@alexander-schranz
Copy link
Contributor Author

@fmonts it doesn't matter both works the same. I used the example provided by the recipe before in config/packages/routing.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants