Skip to content

Use object to represent global scope - #181

Merged
taylorotwell merged 1 commit into
1.xfrom
global-object
Aug 13, 2026
Merged

taylorotwell merged 1 commit into
1.xfrom
global-object

Conversation

@timacdonald

@timacdonald timacdonald commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

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:

use Laravel\Pennant\Facades\Feature;
use Laravel\Pennant\GlobalScope;

Feature::define('...', function (GlobalScope $scope) {
   // ...
});

It also allow developers to reference the global scope when checking or loading multiple values:

use Laravel\Pennant\Facades\Feature;
use Laravel\Pennant\GlobalScope;

Feature::for([new GlobalScope, Auth::user()])->loadAll();

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\GlobalScope implementing FeatureScopeSerializeable to encapsulate the global scope storage key.
  • Updated Decorator::globally() to scope interactions using new GlobalScope instead of the raw __laravel_global string.
  • Updated array/database driver tests to assert that global interactions pass a GlobalScope instance 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.

Comment thread tests/Feature/DatabaseDriverTest.php
@taylorotwell
taylorotwell merged commit a343096 into 1.x Aug 13, 2026
19 checks passed
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.

3 participants