Skip to content

Commit 2e892f1

Browse files
committed
Add Laravel Pennant feature flag integration
1 parent 7c81b41 commit 2e892f1

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ jobs:
154154
# friendsofphp/php-cs-fixer: No need for this package to run phpunit and it conflicts with older Laravel versions
155155
# livewire/livewire: Only supported on Laravel 7.0 and above
156156
# laravel/folio: Only supported on PHP 8.1 + Laravel 10.0 and above
157-
composer remove friendsofphp/php-cs-fixer livewire/livewire laravel/folio --dev --no-interaction --no-update
157+
# laravel/pennant: Only supported on PHP 8.1 + Laravel 10.0 and above
158+
composer remove friendsofphp/php-cs-fixer livewire/livewire laravel/folio laravel/pennant --dev --no-interaction --no-update
158159
159160
# Require the correct versions we want to run phpunit for
160161
composer require \

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": "^7.2 | ^8.0",
2727
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0",
28-
"sentry/sentry": "^4.16.0",
28+
"sentry/sentry": "^4.18.0",
2929
"symfony/psr-http-message-bridge": "^1.0 | ^2.0 | ^6.0 | ^7.0",
3030
"nyholm/psr7": "^1.0"
3131
},
@@ -35,15 +35,16 @@
3535
}
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": "^8.4 | ^9.3 | ^10.4 | ^11.5",
38+
"friendsofphp/php-cs-fixer": "^3.11",
39+
"guzzlehttp/guzzle": "^7.2",
40+
"laravel/folio": "^1.1",
3941
"laravel/framework": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0",
42+
"laravel/pennant": "^1.0",
4043
"livewire/livewire": "^2.0 | ^3.0",
41-
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
42-
"friendsofphp/php-cs-fixer": "^3.11",
4344
"mockery/mockery": "^1.3",
45+
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
4446
"phpstan/phpstan": "^1.10",
45-
"laravel/folio": "^1.1",
46-
"guzzlehttp/guzzle": "^7.2"
47+
"phpunit/phpunit": "^8.4 | ^9.3 | ^10.4 | ^11.5"
4748
},
4849
"autoload-dev": {
4950
"psr-4": {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Sentry\Laravel\Features;
4+
5+
use Sentry\State\Scope;
6+
use Illuminate\Contracts\Events\Dispatcher;
7+
use Sentry\SentrySdk;
8+
use Laravel\Pennant\Feature as Pennant;
9+
use Laravel\Pennant\Events\FeatureResolved;
10+
use Laravel\Pennant\Events\FeatureRetrieved;
11+
12+
class PennantPackageIntegration extends Feature
13+
{
14+
private const FEATURE_KEY = 'pennant';
15+
16+
public function isApplicable(): bool
17+
{
18+
return class_exists(Pennant::class);
19+
}
20+
21+
public function onBoot(Dispatcher $events): void
22+
{
23+
$events->listen(FeatureRetrieved::class, [$this, 'handleFeatureRetrieved']);
24+
}
25+
26+
public function handleFeatureRetrieved($feature): void
27+
{
28+
if (!is_bool($feature->value)) {
29+
return; // rich features are not supported yet
30+
}
31+
32+
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($feature) {
33+
// The value of the feature is not always a bool (Rich Feature Values) but only bools are supported.
34+
// The feature is considered "active" if its value is not explicitly false following Pennant's logic.
35+
$scope->addFeatureFlag($feature->feature, $feature->value !== false);
36+
});
37+
}
38+
}

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ServiceProvider extends BaseServiceProvider
7474
Features\HttpClientIntegration::class,
7575
Features\FolioPackageIntegration::class,
7676
Features\NotificationsIntegration::class,
77+
Features\PennantPackageIntegration::class,
7778
Features\LivewirePackageIntegration::class,
7879
Features\ConsoleSchedulingIntegration::class,
7980
];

0 commit comments

Comments
 (0)