Extending Functionality
You can extend Curtain's functionality in several ways. Here's how to add custom features:
Extending the Service:
namespace App\Services;
use Daycode\Curtain\Services\CurtainService;
class ExtendedCurtainService extends CurtainService
{
public function enableWithNotification(array $options = []): void
{
// Call parent implementation
parent::enable($options);
// Add custom notification logic
if (isset($options['notify'])) {
$this->sendNotifications($options['notify']);
}
}
protected function sendNotifications(array $channels): void
{
foreach ($channels as $channel) {
// Implement notification logic
match ($channel) {
'slack' => $this->notifySlack(),
'email' => $this->notifyEmail(),
default => null
};
}
}
}
Register your extended service:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Services\ExtendedCurtainService;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('curtain', function ($app) {
return new ExtendedCurtainService();
});
}
}
Last updated