Skip to content

Add environment predicates to Environment and remove ApplicationEnvironment::current() - #19

Merged
gustavofreze merged 1 commit into
mainfrom
feat/environment-predicates
Nov 4, 2026
Merged

gustavofreze merged 1 commit into
mainfrom
feat/environment-predicates

Conversation

@gustavofreze

Copy link
Copy Markdown
Member

Breaking changes

  • Environment declares isLocal(), isTest(), isDevelopment(), isStaging() and isProduction(). Classes implementing Environment must add them.
  • ApplicationEnvironment::current() is removed. Use EnvironmentVariable::from(name: 'APP_ENV')->isLocal() and the other predicates, or ApplicationEnvironment::fromAlias() when a case is needed.
  • The message of ApplicationEnvironmentUnrecognized no longer contains the value received. It lists the accepted aliases only.

New

  • Environment predicates on the variable itself:

    EnvironmentVariable::from(name: 'APP_ENV')->isLocal();

    Each predicate matches the value against the aliases of its environment, regardless of casing and surrounding whitespace. A value no environment recognizes raises ApplicationEnvironmentUnrecognized instead of answering false.

Changed

  • Alias resolution in ApplicationEnvironment::fromAlias() is a single constant-table lookup.
  • README reorganized around the predicates, with an upgrade note for 3.0.0.

…nEnvironment::current().

Environment and EnvironmentVariable now answer isLocal, isTest,
isDevelopment, isStaging and isProduction directly, matching the value
against the aliases ApplicationEnvironment owns. An unrecognized value
raises ApplicationEnvironmentUnrecognized instead of answering false, so a
typo never reads as a non-production environment.

This is a breaking change for 3.0.0. Implementers of Environment must add
the five predicates, ApplicationEnvironment::current() is removed in favor
of EnvironmentVariable::from(name: 'APP_ENV')->isX(), and the
ApplicationEnvironmentUnrecognized message lists the accepted aliases
without the value received, so a secret read by mistake does not leak.
@gustavofreze
gustavofreze merged commit 93e7b4f into main Nov 4, 2026
5 checks passed
@gustavofreze
gustavofreze deleted the feat/environment-predicates branch November 4, 2026 13:33
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.

1 participant