PHP SDK
Use Toggly's PHP SDK in PHP applications, Laravel, and WordPress. From 1.0, these are separate Composer packages (Laravel and WordPress pull core as a dependency). See WordPress Integration and Laravel Integration.
Grab the printable PHP cheat sheet (download PDF) — Laravel facade, PHP 8 attributes, Blade.
Installation
Core (vanilla PHP / other frameworks)
composer require toggly/feature-management-php
Laravel (includes core)
composer require toggly/laravel
Laravel package auto-discovery registers the service provider and Toggly facade.
Manual registration is only needed if auto-discovery is disabled.
WordPress (includes core)
composer require toggly/wordpress
Place the package so WordPress loads toggly.php (typically
wp-content/plugins/toggly/). Details: WordPress Integration.
If you previously installed only toggly/feature-management-php and used
Toggly\Laravel\* or Toggly\WordPress\*, also require toggly/laravel or
toggly/wordpress. Core 1.0 no longer ships those namespaces.
Compatibility
The packages retain a PHP 7.4 declared floor and support PHP through 8.5. PHP 8.5 is the current tested runtime. For framework hosts, Laravel 8.0 or newer remains supported; current packed-package checks cover Laravel 10.3.3, 11.6.1, 12.12.2, and 13.10.1. The WordPress plugin retains WordPress 5.0+ support and is currently validated on WordPress 7.1 with PHP 8.5.
See the framework pages for required host configuration.
Quick Start
Laravel
composer require toggly/laravel
php artisan vendor:publish --tag=toggly-config
Configure in .env:
TOGGLY_APP_KEY=your-app-key
TOGGLY_ENVIRONMENT=Production
Use in your code:
use Toggly\Laravel\Facades\Toggly;
if (Toggly::isEnabled('my-feature')) {
// Feature is enabled
}
Native Laravel Patterns:
The Laravel SDK provides native patterns:
- PHP 8 Attributes: Use
#[FeatureGate]and#[FeatureUsage]attributes on controllers and methods - Blade Components: Use
<x-feature>component in Blade templates - Blade Directives: Use
@feature()and@unlessfeature()directives - Automatic Middleware: Attribute-based feature gating without manual route configuration
See the Laravel Integration guide for complete details.
WordPress
composer require toggly/wordpress
Install under wp-content/plugins/toggly/ (so toggly.php is the plugin bootstrap), activate Toggly Feature Management, then configure Settings → Toggly. Use toggly_is_enabled(), the [toggly_feature] shortcode, and WP-Cron hooks. Details: WordPress Integration.
Core Library
For vanilla PHP or other frameworks:
use Toggly\FeatureManagement\Config\TogglySettings;
use Toggly\FeatureManagement\Core\FeatureProvider;
use Toggly\FeatureManagement\Core\FeatureManager;
use Toggly\FeatureManagement\Http\TogglyHttpClient;
// Setup
$settings = new TogglySettings([
'app_key' => 'your-app-key',
'environment' => 'Production'
]);
$httpClient = new TogglyHttpClient(/* PSR-18 client */, /* PSR-17 factory */, $settings->getBaseUrl());
$featureProvider = new FeatureProvider($settings, $httpClient, /* state service */);
$featureManager = new FeatureManager($featureProvider, /* usage stats */, /* secure provider */);
// Use
if ($featureManager->isEnabled('my-feature')) {
// Feature enabled
}
Features
The PHP SDK provides:
- ✅ Feature Flags: Evaluate feature flags with various filters
- ✅ Signed Definitions: ECDSA signature verification for secure feature definitions
- ✅ Real-time Updates: WebSocket support with polling fallback
- ✅ Usage Statistics: Automatic tracking of feature usage
- ✅ Metrics Collection: Custom metrics (measurements, observations, counters)
- ✅ State Change Notifications: Callbacks when features change state
- ✅ Snapshot Providers: Cache, database, and file-based storage
- ✅ Laravel Integration: Native Laravel service provider, facade, middleware, PHP 8 attributes, Blade components, and directives
- ✅ WordPress Plugin: Settings → Toggly,
[toggly_feature]shortcode,toggly_is_enabled(), WP-Cron refresh/stats
Entity context
PHP does not expose registerEntityContext or per-call entity objects.
Pass evaluation context as an array on isEnabled / getVariant. Prefer keys
identity, groups, claims, and request (legacy userId / user_id remain
identity fallbacks). See
Entity & page context for the product
model.
Next Steps
- Learn about Laravel Integration
- Read WordPress Integration
- Read about Core Library Usage
- Review Configuration Options
- Discover Advanced Usage