jolicode/php-os-helper
Lightweight PHP library from JoliCode to detect the current operating system and environment. Provides simple helpers for OS family checks (Windows/macOS/Linux) to adapt code paths, defaults, and tooling behavior across platforms.
Begin by installing the package via Composer:
composer require jolicode/php-os-helper
Then use the OS facade in your code to detect the current environment — for example, in a CLI command or library initializer:
use JoliCode\OS\OS;
if (OS::isWindows()) {
// Windows-specific setup
} elseif (OS::isMac()) {
// macOS-specific behavior
} elseif (OS::isLinux()) {
// Linux-specific path or flag handling
}
The simplest first use case is sanitizing paths in a cross-platform CLI tool — e.g., resolving . to / on Unix-like systems vs \ on Windows — without cluttering business logic.
PlatformService) and inject it wherever needed instead of calling OS::is*() repeatedly.WindowsCommandRunner vs UnixCommandRunner) in dependency injection containers.$config = require __DIR__ . '/config/' . OS::getName() . '.php';
$isWsl = OS::isLinux() && file_exists('/proc/version') && str_contains(file_get_contents('/proc/version'), 'Microsoft');
OS::is*() methods return true only for exact platform matches; use OS::getName() or OS::getFamily() if your use case involves broader categories (e.g., “Unix-like” systems).OS::isLinux() to infer POSIX behavior — some embedded or containerized Linux environments lack required extensions (e.g., pcntl). Fall back to runtime feature checks when possible.OS::debug() outputs detailed platform info including PHP_OS, PHP_OS_FAMILY, and detected names — useful when test environments misreport values.OS::registerPlatformChecker() or wrap its methods with your own logic if needed.How can I help you explore Laravel packages today?