ffi/env
Small PHP utility for detecting the FFI runtime environment. Get FFI status (enabled/disabled/CLI-only/not available), check availability, or assert FFI is usable with clear exceptions/messages. Useful for guarding FFI-dependent code paths.
ext-ffi, ext-sodium, or custom C/C++ integrations).ext-ffi).ext-ffi (if enabled). Installation is a single composer require with no configuration.// app/Providers/AppServiceProvider.php
public function register()
{
if (Runtime::isAvailable()) {
$this->app->singleton(FFIService::class, fn() => new FFIService());
}
}
Status::DISABLED in CI).Runtime::isAvailable() may return true in CLI but false in web (or vice versa) due to SAPI differences.Runtime::getStatus() to handle granular cases (e.g., Status::CLI_ENABLED).ext-ffi is experimental in some PHP versions (e.g., PHP 8.1–8.3). Breaking changes in PHP 8.4+ may require updates.^1.0 in composer.json and monitor PHP RFCs.assertAvailable()) throws exceptions early, which may disrupt workflows.Status::CLI_ENABLED be handled?league/ffi)? If so, how will conflicts be resolved?php -S, php-fpm, phpdbg)?ext-ffi deprecations or PHP version drops? Will the package require updates?php artisan ffi:compile).extension_loaded('ffi') is less robust (misses SAPI-specific cases like CLI_ENABLED).FFI::cdef(), FFI::load() calls).extension_loaded('ffi') checks with Runtime::isAvailable().assertAvailable() to Artisan commands or service providers.config('app.ffi_enabled')) to toggle behavior during migration.| Component | Compatibility Notes |
|---|---|
| PHP 8.1–8.4 | Fully supported; package handles deprecations in 8.4. |
| Laravel 9/10 | No conflicts; works with Laravel’s service container. |
| FFI Extension | Must be installed (pecl install ffi) but not enforced by this package. |
| SAPIs | Explicitly checks cli, embed, phpdbg, micro, and web SAPIs. |
| Composer | MIT-licensed; no conflicts with Laravel’s dependencies. |
ext-ffi is available in the target environment (e.g., Docker, server).Dockerfile:
RUN pecl install ffi && docker-php-ext-enable ffi
composer require ffi/env
bootstrap/app.php:
if (!Runtime::isAvailable()) {
throw new RuntimeException('FFI extension is required.');
}
if (app()->runningInConsole() && !Runtime::isAvailable()) {
$this->error('FFI is required for this command.');
}
phpunit.xml:
<env name="FFI_AVAILABLE" value="false" /> <!-- Simulate disabled FFI -->
Runtime::getStatus() in tests to assert expected behavior.^1.0 covers PHP 8.1+).ext-ffi stability via PHP RFCs and PECL issues.ffi/env:^1.0.2).Runtime::getStatus() in Laravel’s cache if checking repeatedly (e.g., in middleware).Runtime::getStatus() provides clear error codes for troubleshooting (e.g., Status::DISABLED in web vs. CLI_ENABLED in CLI).\Log::debug('FFI Status', ['status' => Runtime::getStatus()]);
ext-ffi is enabled in php.ini (not just installed).php -S, php-fpm, phpdbg).$status = Cache::remember('ffi.status', now()->addHours(1), fn() => Runtime::getStatus());
| Scenario | Impact | Mitigation Strategy |
|---|
How can I help you explore Laravel packages today?