Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Document defining Pennant features externally #10027

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pennant.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [Adding Custom Pennant Drivers](#adding-custom-pennant-drivers)
- [Implementing the Driver](#implementing-the-driver)
- [Registering the Driver](#registering-the-driver)
- [Defining Features Externally](#defining-features-externally)
- [Events](#events)

<a name="introduction"></a>
Expand Down Expand Up @@ -1022,7 +1023,7 @@ class RedisFeatureDriver implements Driver

Now, we just need to implement each of these methods using a Redis connection. For an example of how to implement each of these methods, take a look at the `Laravel\Pennant\Drivers\DatabaseDriver` in the [Pennant source code](https://github.com/laravel/pennant/blob/1.x/src/Drivers/DatabaseDriver.php)

> [!NOTE]
> [!NOTE]
> Laravel does not ship with a directory to contain your extensions. You are free to place them anywhere you like. In this example, we have created an `Extensions` directory to house the `RedisFeatureDriver`.

<a name="registering-the-driver"></a>
Expand Down Expand Up @@ -1075,6 +1076,32 @@ Once the driver has been registered, you may use the `redis` driver in your appl

],

<a name="defining-features-externally"></a>
### Defining Features Externally

If your driver is a wrapper around a third-party feature flag platform, you will likely define features on the platform rather than using Pennant's `Feature::define` method. If that is the case, your custom driver should also implement the `Laravel\Pennant\Contracts\DefinesFeaturesExternally` interface:

```php
<?php

namespace App\Extensions;

use Laravel\Pennant\Contracts\Driver;
use Laravel\Pennant\Contracts\DefinesFeaturesExternally;

class FeatureFlagServiceDriver implements Driver, DefinesFeaturesExternally
{
/**
* Get the features defined for the given scope.
*/
public function definedFeaturesForScope(mixed $scope): array {}

/* ... */
}
```

The `definedFeaturesForScope` method should return a list of feature names defined for the provided scope.

<a name="events"></a>
## Events

Expand Down