Repository navigation
Add environment predicates to Environment and remove ApplicationEnvironment::current() - #19
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking changes
EnvironmentdeclaresisLocal(),isTest(),isDevelopment(),isStaging()andisProduction(). Classes implementingEnvironmentmust add them.ApplicationEnvironment::current()is removed. UseEnvironmentVariable::from(name: 'APP_ENV')->isLocal()and the other predicates, orApplicationEnvironment::fromAlias()when a case is needed.ApplicationEnvironmentUnrecognizedno longer contains the value received. It lists the accepted aliases only.New
Environment predicates on the variable itself:
Each predicate matches the value against the aliases of its environment, regardless of casing and surrounding whitespace. A value no environment recognizes raises
ApplicationEnvironmentUnrecognizedinstead of answeringfalse.Changed
ApplicationEnvironment::fromAlias()is a single constant-table lookup.