Use object to represent global scope - #181
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a dedicated GlobalScope value object to represent Pennant’s global scope, so feature resolvers and scoped interactions can work with a typed object instead of the string identifier.
Changes:
- Added
Laravel\Pennant\GlobalScopeimplementingFeatureScopeSerializeableto encapsulate the global scope storage key. - Updated
Decorator::globally()to scope interactions usingnew GlobalScopeinstead of the raw__laravel_globalstring. - Updated array/database driver tests to assert that global interactions pass a
GlobalScopeinstance into resolvers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Feature/DatabaseDriverTest.php | Updates/extends coverage to ensure global interactions pass a GlobalScope instance and persist the expected scope key. |
| tests/Feature/ArrayDriverTest.php | Adjusts assertions to validate GlobalScope is passed into resolvers for global interactions. |
| src/GlobalScope.php | Adds the new GlobalScope scope object with serialization for storage. |
| src/Drivers/Decorator.php | Switches globally() to use GlobalScope instead of the string identifier. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Improves on #180 by adding a class to represent the global scope.
The stored string is still the same. This just ensures that developers don't have to deal with the stringy value and can instead use the object in the resolve function:
It also allow developers to reference the global scope when checking or loading multiple values:
This is a small breaking change for anyone typing the resolve function, but I think it is worth it given we just released the feature and have not advertised it yet.