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

Php Os Helper Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Centralize OS checks: Encapsulate OS-specific logic in a single service (e.g., PlatformService) and inject it wherever needed instead of calling OS::is*() repeatedly.
  • Strategy-based branching: Use OS detection to return appropriate strategies (e.g., WindowsCommandRunner vs UnixCommandRunner) in dependency injection containers.
  • Configuration resolution: Load OS-specific config files at runtime:
    $config = require __DIR__ . '/config/' . OS::getName() . '.php';
    
  • Fallback composition: Combine detection with environment variables for edge cases (e.g., WSL):
    $isWsl = OS::isLinux() && file_exists('/proc/version') && str_contains(file_get_contents('/proc/version'), 'Microsoft');
    

Gotchas and Tips

  • ⚠️ 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).
  • ❗ Don’t rely solely on 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.
  • 🔍 For debugging, OS::debug() outputs detailed platform info including PHP_OS, PHP_OS_FAMILY, and detected names — useful when test environments misreport values.
  • 🧩 This package avoids external dependencies, so it won’t auto-detect exotic or deviant OSes (e.g., FreeBSD or Android). Extend via OS::registerPlatformChecker() or wrap its methods with your own logic if needed.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport