sebastian/environment
sebastian/environment helps PHP developers detect runtime details (PHP vs HHVM, OS, architecture, 32/64-bit, debugging extensions) to choose runtime-specific execution paths. Commonly used by testing tools to adapt behavior to the environment.
config('app.env').local vs. production). Laravel’s native helpers suffice for 80% of cases; this package targets the remaining 20%.Runtime as a singleton for global access:
$this->app->singleton(Runtime::class, fn() => new \SebastianBergmann\Environment\Runtime());
Environment::isPhp80()) for consistency.config(['app.supported_php_versions' => Environment::getSupportedPhpVersions()]);
Runtime, Environment, OperatingSystem) with clear methods (e.g., isHhvm(), getPhpVersion()).version_compare(PHP_VERSION, '8.0') with Environment::isPhp80() for marginal gains.$_ENV or symfony/dotenv for that).phpversion() or Laravel’s app()->environment()? Pitch as a "standardized" alternative.$this->app->instance(Runtime::class, MockRuntime::expectingIsPhp80(true));
app()->environment(): Better for high-level checks (e.g., local, production).phpversion(), PHP_SAPI—less maintainable and no HHVM support.composer require --dev sebastian/environment
// app/Providers/EnvironmentServiceProvider.php
public function register() {
$this->app->singleton(\SebastianBergmann\Environment\Runtime::class);
}
// app/Facades/Environment.php
public static function isPhp80() {
return app(Runtime::class)->isPhpVersion('8.0');
}
// Before
if (version_compare(PHP_VERSION, '8.0.0') >= 0) { ... }
// After
if (Environment::isPhp80()) { ... }
if (Environment::isHhvm()) {
Log::warning('HHVM is deprecated; switching to PHP compatibility mode.');
}
phpunit.xml or GitHub Actions:
<php>
<ini name="memory_limit" value="256M"/>
<env name="PHP_VERSION" value="Environment::getPhpVersion()"/>
</php>
OperatingSystem::isLinux()) for path/permission logic.Runtime::getBinary() for php.exe vs. php).app()->isPhp80()).Runtime::isHhvm() clarify intent vs. raw defined('HHVM_VERSION').How can I help you explore Laravel packages today?