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

Os Info Laravel Package

boson-php/os-info

Lightweight PHP library to detect and describe the current operating system, exposing basic OS name/version/arch details for CLI and server environments. Useful for cross-platform scripts, installers, and runtime diagnostics.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require boson-php/os-info
    

    No additional configuration is required—this is a lightweight, dependency-free package.

  2. First Use Case Quickly fetch OS details in a Laravel controller or service:

    use Boson\OSInfo\OSInfo;
    
    $osInfo = new OSInfo();
    $osDetails = $osInfo->getOSInfo();
    
    // Example output:
    // [
    //   'name' => 'Linux',
    //   'version' => '5.4.0-135-generic',
    //   'family' => 'Debian',
    //   'kernel' => '5.4.0-135-generic',
    //   ...
    // ]
    
  3. Where to Look First

    • Class Reference: OSInfo (minimal docs, but simple API).
    • Test Suite: Check tests/ for edge-case examples (e.g., Windows, macOS, containers).
    • Source Code: src/OSInfo.php for direct inspection of parsing logic.

Implementation Patterns

Core Workflows

  1. OS Detection in Middleware Use to dynamically adjust behavior (e.g., redirect Windows users to a different setup guide):

    namespace App\Http\Middleware;
    
    use Boson\OSInfo\OSInfo;
    use Closure;
    
    class OSDetector
    {
        public function handle($request, Closure $next)
        {
            $osInfo = (new OSInfo())->getOSInfo();
            if ($osInfo['name'] === 'Windows') {
                return redirect()->route('windows.setup');
            }
            return $next($request);
        }
    }
    
  2. Feature Flagging by OS Enable/disable features based on OS compatibility:

    $osInfo = (new OSInfo())->getOSInfo();
    if ($osInfo['family'] === 'Darwin') {
        Feature::enable('mac-specific-feature');
    }
    
  3. Logging/Monitoring Log OS details for analytics or debugging:

    \Log::info('User OS', [
        'os' => $osInfo->getOSInfo(),
        'user_agent' => $request->userAgent(),
    ]);
    

Integration Tips

  • Caching: Cache results if OS detection is called frequently (e.g., in middleware):
    $osInfo = Cache::remember('os_info', 86400, fn() => (new OSInfo())->getOSInfo());
    
  • Laravel Service Provider: Bind OSInfo to the container for DI:
    $this->app->singleton(OSInfo::class, fn() => new OSInfo());
    
  • Artisan Commands: Use for system diagnostics:
    $osInfo = app(OSInfo::class)->getOSInfo();
    $this->info("Server OS: {$osInfo['name']} {$osInfo['version']}");
    

Gotchas and Tips

Pitfalls

  1. Container/VM Detection

    • Returns unknown for some containerized environments (e.g., Docker). Handle gracefully:
      $osInfo = (new OSInfo())->getOSInfo();
      if ($osInfo['name'] === 'unknown') {
          $osInfo['name'] = 'Containerized';
      }
      
    • Workaround: Combine with php-uname for richer detection.
  2. Windows Quirks

    • Version parsing may differ across Windows builds. Validate output:
      if (strpos($osInfo['version'], '10.0') === 0) {
          $osInfo['version'] = 'Windows 10+';
      }
      
  3. Performance

    • Avoid instantiating OSInfo repeatedly in loops. Reuse the object or cache results.
  4. Edge Cases

    • macOS: May return Darwin as name (not macOS). Normalize:
      $osInfo['name'] = $osInfo['name'] === 'Darwin' ? 'macOS' : $osInfo['name'];
      

Debugging Tips

  • Verbose Output: Dump raw data to debug:
    dd((new OSInfo())->getOSInfo());
    
  • Test Locally: Run tests to see how the package handles your OS:
    composer test
    

Extension Points

  1. Custom Parsing Extend the class to add OS-specific logic:

    class ExtendedOSInfo extends OSInfo
    {
        public function isWindows11(): bool
        {
            $info = $this->getOSInfo();
            return $info['name'] === 'Windows' && strpos($info['version'], '10.0.22000') === 0;
        }
    }
    
  2. Add New OS Families Modify the parsing logic in src/OSInfo.php to support niche systems (e.g., FreeBSD, Alpine Linux).

  3. Integration with Laravel Scout Use OS data for search filtering:

    User::where('os_family', $osInfo['family'])->search($query);
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky