decodelabs/systemic

Easy access to system and environment info

v0.11.14 2024-08-21 20:41 UTC

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

System processes and information at your fingertips

Systemic offers an easy to use frontend to launching and controlling processes and accessing system information.

Get news and updates on the DecodeLabs blog.

Installation

Install via composer:

composer require decodelabs/systemic

Usage

Importing

Systemic uses Veneer to provide a unified frontage under DecodeLabs\Systemic. You can access all the primary functionality via this static frontage without compromising testing and dependency injection.

Process launching

Launch new processes:

use DecodeLabs\Systemic;

$dir = 'path/to/working-directory';

// Launch and capture output of a process
echo Systemic::capture(['ls', '-al'], $dir)->getOutput();

// Launch and capture output of a process with raw string command (not escaped)
echo Systemic::capture('ls -al', $dir)->getOutput();

// Launch and capture output of a script
echo Systemic::capture(['myPhpScript.php'], $dir)->getOutput();

// Launch a background task
$process = Systemic::launch(['make', 'install']);

// Launch a background script
$process = Systemic::launchScript(['myPhpScript.php'], $dir);

// Run a piped pseudo terminal process
$success = Systemic::run(['interactive-app', '--arg1'], $dir);

// Run a piped pseudo terminal script
$success = Systemic::runScript(['myPhpScript.php', '--arg1'], $dir);

// Custom escaped command
$success = Systemic::command(['escaped', 'arguments'])
    ->setWorkingDirectory($dir)
    ->addSignal('SIGSTOP') // Pass SIGSTOP through when caught
    ->setUser('someuser') // Attempt to use sudo to run as user
    ->run();

// Custom raw command with env arguments
$result = Systemic::command('echo ${:VARIABLE} | unescaped-command', [
        'VARIABLE' => 'Hello world'
    ])
    ->setWorkingDirectory($dir)
    ->capture();

OS info

Get information about the current OS:

use DecodeLabs\Systemic;

// OS info
echo Systemic::$os->getName(); // Linux | Windows | Darwin
echo Systemic::$os->getPlatformType(); // Unix | Windows
echo Systemic::$os->getDistribution(); // eg Ubuntu or High Sierra, etc
echo Systemic::$os->getVersion(); // System version info
echo Systemic::$os->getRelease(); // System version number
echo Systemic::$os->getHostName(); // System hostname

// Find binaries on the system
echo Systemic::$os->which('php'); // eg /usr/local/bin/php

Windows

Please note, OS and Process support on Windows is currently extremely sketchy - this will be fleshed out soon!

Locale & Timezone

Looking for Locale and Timezone info? This has moved to Cosmos.

Licensing

Systemic is licensed under the MIT License. See LICENSE for the full license text.