Terminal: An Elegant Wrapper around the Symfony Process Component

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:

Terminal::in(storage_path('sites/123'))
    ->timeout(120)
    ->retries(3)
    ->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
$response->throw();

// You can access the symfony process
$response->process();

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

Here are a few more neat examples from the readme:

// Passing data to the command
Terminal::with([
    '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
Terminal::withEnvironmentVariables([
    '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.

Filed in: News / packages

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full-Stack Engineer
[REMOTE: USA Only] All Other Applications Will be Rejected Immediately"
Curricula
Senior Full Stack PHP Developer
Canada
Motto Design Studio
👉 Looking for Senior Back-End Laravel API Developer - Immediate (Full-time Contractor) 🎉
Remote
ApproveMe.com // The Document Signing Experience™
Senior Full-Stack Developer
Remote, USA Only
Givebutter
Senior Full Stack Engineer
Remote / Los Angeles, USA
Entertainment Media