php-standard-library/os
Type-safe OS detection for PHP via an OperatingSystemFamily enum. Quickly identify Windows, macOS, Linux, and more without brittle string checks. Part of PHP Standard Library; lightweight and focused on reliable environment detection.
OperatingSystemFamily) for OS detection, which is valuable in Laravel applications requiring cross-platform compatibility (e.g., CLI tools, environment-specific configurations, or feature flags). It aligns well with Laravel’s dependency injection and service container, enabling clean abstraction of OS-specific logic.app() helper and service container can leverage this package to inject OS detection into services, middleware, or even facade bindings (e.g., config('os.family')). The enum design reduces runtime type errors compared to string-based checks.composer require php-standard-library/os
AppServiceProvider::boot()) to set a global OS family variable or publish config files for environment-specific overrides.php_uname()).cache()->remember).strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') or supplement them?APP_PATH_SEPARATOR) be published as config files or managed via environment variables?$this->app->singleton(OperatingSystemFamily::class, fn() => OperatingSystemFamily::fromCurrent());
Os::family()) for convenience.mix.js('windows.js', ['os' => 'windows'])).@if(Os::is(OperatingSystemFamily::Windows))).// Before
if (str_contains(PHP_OS, 'Darwin')) { ... }
// After
if (Os::is(OperatingSystemFamily::MacOS)) { ... }
config/os.php) to centralize OS-specific settings.Deprecates trait or runtime warnings to phase out legacy checks.AppServiceProvider.Os::family()).config/os.php) for environment overrides.@requiresPhp('>=8.1') @os(OperatingSystemFamily::Linux)).OperatingSystemFamily in unit tests.@os(macos)) and run tests in parallel CI environments.README.md section in the project for OS-specific configurations or limitations.FreeBSD).OperatingSystemFamily::Windows").SUPPORTED_OS.md or similar.OperatingSystemFamily::fromCurrent() might misidentify the OS in rare cases (e.g., custom Linux distros).php_uname() or log warnings for unsupported platforms.OperatingSystemFamily::fromCurrent() could be called in an unsupported context (e.g., during bootstrapping).booted() method or lazy-load the enum.config/os.php might diverge across environments.env() or environment-specific config files (e.g., config/os-windows.php).CONTRIBUTING.md explaining the enum’s usage and conventions.// Good: Use the enum
if (Os::is(OperatingSystemFamily::Windows)) { ... }
// Avoid: String comparisons
if (str_contains(PHP_OS, 'WIN')) { ... }
How can I help you explore Laravel packages today?