Environment: empty .env values give the default, the new traits and updateRow() (3.2.0)

Abierto
#194 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
75/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

Read the 3.2.x Environment code and the current docs under v3.0/packages/environment/, plus v3.0/upgrade-guide.md; the issue names the sections and line ranges to update. Check the Config typed reader contract alongside Environment so their behavior and cross-links agree. Update the docs for the empty-value defaults, traits, updateRow() behavior, and upgrade steps; done when every statement matches the code and the grep check includes ValueTrait and EnvFileTrait.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

Framework 3.2.0 changes the Environment package (quantum-php/framework#709):

  • env_bool() and env_int() (environment()->getBool() / getInt()) treat an empty value, KEY= or a KEY line without =, as not set and return the default. They gave false or threw EnvException::invalidValue(). This is a breaking change: TWO_FA= with env_bool('TWO_FA', true) now leaves two-factor authentication on; TWO_FA=false turns it off. env() still returns the raw value.
  • Environment loads the .env file itself; ReadTrait (renamed from ValueTrait) reads and the new WriteTrait writes (updateRow()); EnvFileTrait is removed.
  • updateRow() finds the key and its value as the file has them (KEY="…", also over several lines, KEY='…', KEY=value, KEY without =), keeps a comment after the value, writes the new value as it is given ($ and \ included), and throws EnvException::fileNotFound() instead of writing an empty file when the replacement fails. A line it cannot find as it was read, such as export KEY=value, is left unchanged.

The docs still describe the old traits and say an empty value gives false.

Changes

  1. Environment package (v3.0/packages/environment/):
    • overview.md:16: the traits are AppEnvTrait, ReadTrait and WriteTrait.
    • architecture.md:27-33, "How Environment is organised": Environment holds its state, load() and the file lookup and parsing; ReadTrait the readers; WriteTrait updateRow(). :60-62, "Mutation model": how updateRow() finds the line, keeps a comment, and what it leaves unchanged.
    • contracts.md:21-33, "Typed reader contract": an empty value ('' or null) is not set and gives the default; a missing key without a default gives false / 0. :49-58, "Mutability contract": the updateRow() guarantees above, and fileNotFound() when the replacement fails.
    • helpers.md:32-56: env_bool() / env_int() return the default for an empty value.
    • usage.md:23, "Reading booleans and numbers": an empty value gives the default (it says false today), with the TWO_FA= example.
  2. The env and config readers differ on purpose: .env is outside input and often incomplete, so env_bool() / env_int() are forgiving (a missing or empty value gives the default, or false / 0), while config()->getBool() / getInt() without a default state a required key and throw ConfigException::missingKey(). Both pages say this in the same words and link to each other:
    • environment/contracts.md, "Typed reader contract", with a link to the Config typed reader contract;
    • config/contracts.md:76-90, "Typed reader contract", with a link to the Environment typed reader contract.
  3. v3.0/upgrade-guide.md, "Upgrading from 3.1 to 3.2": a new section before "Check the upgrade" on empty .env values (the TWO_FA= example and TWO_FA=false), the renamed and removed traits (a class of your own that used ValueTrait or EnvFileTrait), and what updateRow() now replaces; the check grep also looks for ValueTrait and EnvFileTrait.

Every statement is checked against the 3.2.x code. The changes wait in staging until 3.2.0 is released.

Related

  • quantum-php/framework#709, PR quantum-php/framework#710, merge-up quantum-php/framework#711
Lenguaje dominante
Sin datos de lenguaje
Estrellas
3
Forks
1
Merge medio
2 min
PR fusionados (30 d)
27

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de quantum-php/docs

Todos los issues de quantum-php/docs

Issues similares

Más issues de Documentation

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.