Environment: choose the environment from --env or APP_ENV, with shared/config/env.php as a deprecated fallback
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Feature
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Bereich
- backend, cli, devtools, documentation, infrastructure, testing
Rechercherichtung
Start with Environment::resolveEnvironmentFile(), the console boot stages, and the tests listed in the issue; check how raw argv is available before Symfony parses options. Trace environment selection through file loading, console commands, and ServeCommand, then review the docs and upgrade guide. Done means the precedence, fallback deprecation, command behavior, tests, and documentation described here are covered.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
Quantum chooses its environment, and with it the .env file, only from app_env in shared/config/env.php, a committed file. Laravel, Symfony, Rails, Next.js, Django and CodeIgniter take the environment name from the real environment (APP_ENV, NODE_ENV, RAILS_ENV, …) or a command-line option, so the same code runs as staging on one server and production on another. This ticket adds --env and APP_ENV in front of env.php, as a transitional step: env.php keeps working as the fallback and is deprecated, to be removed in 3.3.0.
Current behavior
Environment::resolveEnvironmentFile()readsapp_envfromshared/config/env.php(defaultproduction) and loads.envforproduction,.env.<name>otherwise. A missingenv.phpthrowsEnvException::fileNotFound().- The file is loaded with
Dotenv::createArrayBacked(), so each execution keeps its values in its ownEnvironmentand nothing is written to$_ENV,$_SERVERorputenv()(#456, no state shared between executions). This stays as it is.
Proposed change
1. The order
The environment name comes from the first of:
--env=<name>on aphp qtcommandAPP_ENVfrom the real environment, read withgetenv(), then$_SERVER;$_ENValone is not used, it is empty whenvariables_orderis the common"GPCS". ($_SERVERalso holds request headers, but asHTTP_*keys, so a client cannot setAPP_ENV.)app_envinshared/config/env.php, deprecatedproduction
The file choice is unchanged: production → .env, any other name → .env.<name>. A missing env.php is no longer an error; without 1–3 the environment is production. getAppEnv() and the is…() checks return the chosen name.
2. --env on php qt
- The console boot loads the environment (
ResolveEnvironmentStage, thenLoadEnvironmentStage) before Symfony parses the input, so the value is read from the raw arguments ($_SERVER['argv']) and handed toEnvironmentbeforeload(). It is also declared as a global option of the console application, so Symfony accepts it on every command. - Commands that write the environment file, such as
php qt core:key --env=staging, write the chosen file (.env.staging). php qt serve --env=staging:ServeCommandstarts PHP's built-in server withproc_open(), which inherits the parent's environment. It passesAPP_ENVto that process, so the served requests use the same environment.
3. Deprecate shared/config/env.php
- When
app_envinenv.phpdecides the environment (no--env, noAPP_ENV), report anE_USER_DEPRECATEDthat namesAPP_ENVand--envas the replacement. - Both adapters load the environment before
SetupErrorHandlerStage, so a deprecation raised during loading would reach PHP's default handler instead of the application's log.Environmentrecords thatenv.phpdecided, and the deprecation is reported once the error handler is set up. - The core's tests choose
testingthroughtests/_root/shared/config/env.php; they move to<env name="APP_ENV" value="testing"/>inphpunit.xml, and a test keeps covering theenv.phpfallback. - Removal in 3.3.0 is a separate ticket.
Setting APP_ENV (for the docs)
- Nginx + PHP-FPM:
fastcgi_param APP_ENV staging;in the site config, orenv[APP_ENV] = stagingin the FPM pool. With FPM's defaultclear_env = yes, the machine's own variables do not reach PHP unless the pool setsclear_env = noor anenv[...]line. - Apache:
SetEnv APP_ENV stagingin the virtual host or.htaccess. - Docker:
docker run -e APP_ENV=production, orenvironment:indocker-compose.yml; with an FPM image, theclear_envnote applies. - Kubernetes:
env:in the pod spec, or a ConfigMap. - Command line:
APP_ENV=staging php qt …, or--env=staging.
Out of scope
- Reading other variables from the real environment (only
APP_ENVis read here). - Making the
.envfile optional. core:envcreating.env.<name>.- Removing
env.php(3.3.0), and how a developer chooseslocalwithout it, decided there.
Breaking changes
None for applications that set neither APP_ENV nor --env. An application whose server or container already sets APP_ENV (for another purpose) now loads the file of that name. A changelog entry and an upgrade-guide note explain the order and the deprecation.
Tests
- Each step of the order wins over the later ones;
productionwhen nothing is set; a missingenv.phpwithAPP_ENVset. APP_ENVread throughgetenv()and through$_SERVER.--envread before the environment loads, and accepted by Symfony on any command.php qt core:key --env=stagingwrites.env.staging.php qt serve --env=stagingpassesAPP_ENV=stagingto the server process.- The deprecation is reported only when
env.phpdecides, after the error handler is set up, once per execution.
Docs
packages/environment/: the order, the deprecation,APP_ENVand--env.- A section on setting
APP_ENVon Nginx/PHP-FPM, Apache, Docker, Kubernetes and the command line, with theclear_envnote. cli: the global--envoption andserve --env.- The 3.2 upgrade guide: the order and the move from
env.phptoAPP_ENV.
The starter project drops shared/config/env.php and documents APP_ENV in its own ticket, at its 3.2 release.
- Vorherrschende Sprache
- PHP
- Sterne
- 44
- Forks
- 22
- Ø Merge
- 2 Std. 57 Min.
- Gemergte PRs (30 T.)
- 52
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus quantum-php/framework
-
tech debt testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
quantum-php/framework#696 ·
Maintainer antworten meist innerhalb von 1 Tag
-
routing testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
quantum-php/framework#547 ·
Maintainer antworten meist innerhalb von 1 Tag
-
breaking change enhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
quantum-php/framework#715 ·
Maintainer antworten meist innerhalb von 1 Tag
-
refactoring tech debt
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
quantum-php/framework#712 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Raise PHPStan to level 9Offenrefactoring tech debt
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
quantum-php/framework#693 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in quantum-php/framework
Ähnliche Issues
-
OCM: shares using the `embedded` protocol are rejected with "Missing sharedSecret in protocol"Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ExpressionEngine/ExpressionEngine#5493 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
"Attempt to read property 'username' on null" error after a user is deletedEvtl. vergeben @dicksonlaw583 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
omeka/plugin-SimplePages#49 ·
-
not confirmed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 1 Tag