Allow env config for attributes - #13666
Closed
timkelty wants to merge 3 commits into
Closed
Conversation
Member
|
timkelty
marked this pull request as draft
January 24, 2024 02:57
…ttributes # Conflicts: # src/helpers/App.php
Contributor
There was a problem hiding this comment.
Pull request overview
Updates craft\helpers\App::envConfig() to support Yii models by deriving configurable keys from model attributes (instead of only reflecting public properties), enabling environment overrides to work for attribute-backed settings.
Changes:
- Expand
envConfig()to accept an object or class-string and detect Yii models. - Build env override keys from either model
attributes()or reflected public properties. - Factor out
EnvNameattribute lookup into a dedicated helper (envNameForProperty()).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $envName = strtoupper(StringHelper::toSnakeCase($prop->getName())); | ||
| } | ||
| $reflection = new ReflectionClass($class); | ||
| $isModel = $reflection->isSubclassOf(Model::class); |
Comment on lines
+217
to
+218
| // CONFLICT-REVIEW: model attributes() can include names that aren’t backed by a real property | ||
| // (behaviors, magic properties), so only reflect on the ones that are. |
Comment on lines
+171
to
173
| * @param object|string $class The class name or object | ||
| * @phpstan-param class-string|object $class | ||
| * @param string|null $envPrefix The environment variable name prefix |
Member
|
Closing |
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.
Description
Detects if you pass
\craft\helpers\App::envConfiga Model, and if so, uses the the model's attributes instead of just getting public properties.This allows config overrides to work if you have an attribute with a getter/setter.
Another option could be to just allow you to pass an array of properties to override, so when you called
\craft\helpers\App::envConfig, you could just pass if your model's attributes.One potential issue here might be if you have a read-only attribute (no setter), and you try to set the corresponding env for it, it will throw.