Terminal: An Elegant Wrapper around the Symfony Process Component
Dodato 6 months ago u Laravel od Milan Janković

Terminal: An Elegant Wrapper around the Symfony Process Component

Terminal is a neat PHP package by Titas Gailius that provides a “wrapper around Symfony’s Process component.” It has a fluent interface, which makes running terminal commands a breeze:

    ->run('wp cli update');

In the most simple form, a command might look like the following—which removes a lot of boilerplate and lower-level details of the wonderful Symfony Process component:

$response = Terminal::run('rm -rf vendor');

Here are some things you can do with the response from the run command:

$response->code() : int;
$response->ok() : bool;
$response->successful() : bool;

$response->lines() : array;
$response->output() : string;
(string) $response: string;

// Terminal captures exceptions that you can throw

// You can access the symfony process

// All calls not found on the Response are passed to Symfony process
// \Symfony\Component\Process\Process::isRunning()

Here are a few more neat examples from the readme:

// Passing data to the command
    'firstname' => 'John',
    'lastname' => 'Doe',
])->run('echo Hello, {{ $firstname}} {{ $lastname }}');

// Retries and duration between each retry
Terminal::retries(3, 100)->run('rm -rf vendor');

// Environment variables
    'APP_ENV' => 'testing',
])->run('rm -rf $DIRECTORY');

You can learn more about this package, get full installation instructions, and view the source code on GitHub at TitasGailius/terminal.

Ostavite komentar

Treba vam web sajt ?