Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Environment

Environment Laravel Package

sebastian/environment

sebastian/environment helps PHP libraries handle runtime-specific execution paths by detecting and describing the current environment (PHP version, features, etc.). Useful for writing portable code that adapts to different runtimes and configurations.

View on GitHub
Deep Wiki
Context7

Provides functionality that helps writing PHP code that has runtime-specific execution paths

Frequently asked questions about Environment
How do I replace manual PHP_SAPI checks in Laravel Artisan commands with sebastian/environment?
Replace `if (PHP_SAPI === 'cli')` with `Host::supportsColor()` or `Runtime::isCli()` from sebastian/environment. For example, use `$this->output->setDecorated(Host::supportsColor())` in your Artisan command’s `handle()` method. This ensures consistent color support across all environments, including Docker and CI/CD pipelines.
Does sebastian/environment work with Laravel 10+ and PHP 8.4?
Yes, use version `^9.2` of sebastian/environment for Laravel 10+ (PHP 8.4+). For Laravel 9.x (PHP 8.2–8.3), pin to `^8.0`. Always check the [Laravel version requirements](https://laravel.com/docs/10.x/upgrade) to avoid compatibility issues.
Can I use this package to enforce immutable settings in Laravel Sail/Docker?
Absolutely. Call `Runtime::getSettingsNotChangeableAtRuntime()` during Laravel’s bootstrapping (e.g., in `AppServiceProvider`) to detect critical settings like `opcache.enable` or `memory_limit`. Log warnings or throw exceptions if these are modified at runtime, ensuring consistency in containerized environments.
How does sebastian/environment handle TTY detection in Docker or CI/CD?
The package abstracts TTY detection but may still misreport in Docker. Fall back to the `FORCE_COLOR` environment variable (e.g., `FORCE_COLOR=1` in GitHub Actions) or manually override with `Host::setSupportsColor(true)`. This ensures reliable terminal output in headless environments.
Is sebastian/environment compatible with PestPHP for test output?
Yes. Use `Host::supportsColor()` in PestPHP test suites to standardize CLI output formatting. For example, replace `if (PHP_SAPI === 'cli')` in test helpers with `Host::supportsColor()` to ensure consistent test output across local and CI environments.
What’s the performance impact of runtime checks in Artisan commands?
Minimal. sebastian/environment caches runtime checks internally, so repeated calls (e.g., `Host::supportsColor()`) are fast. Benchmark in your Artisan commands if latency is critical, but the overhead is typically negligible for CLI tools.
How do I integrate sebastian/environment into Laravel’s configuration validation?
Hook into Laravel’s bootstrapping (e.g., `AppServiceProvider::boot()`) to validate immutable settings. Use `Runtime::getSettingsNotChangeableAtRuntime()` to check for runtime-modifiable configurations like `opcache` or `memory_limit`, then log warnings or enforce defaults.
Are there alternatives to sebastian/environment for Laravel CLI checks?
For basic CLI detection, you could use Symfony’s `StreamOutput::hasColorSupport()` (built into Artisan), but sebastian/environment provides broader runtime detection (PHP version, OS, immutable settings) and is more maintainable for complex environments like Docker or CI/CD.
Should I use sebastian/environment in production or only for testing?
Use it in both. The package is lightweight and helps standardize CLI behavior across all environments. For example, enforce `FORCE_COLOR=1` in production CI/CD pipelines to eliminate flaky terminal output, while also using it in local development for consistent Artisan output.
How do I migrate from manual ANSI checks to sebastian/environment in Laravel?
Start with low-risk changes: replace `if (PHP_SAPI === 'cli')` with `Host::supportsColor()` in Artisan commands. For example, swap `$this->output->setDecorated(true)` with `$this->output->setDecorated(Host::supportsColor())`. Test thoroughly in local, Docker, and CI environments before rolling out globally.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata