Titas Gailius
Posted on March 22, 2020
Terminal
An elegant wrapper around Symfony's Process component.
Why?
I've been developing hosting related services for almost 4 years now.
To complete various tasks, I have to write PHP code that executes bash scripts almost on a daily basis. Let's say you want to set up automatic updates for WordPress or put your site to the maintenance mode.
That's where Terminal comes in handy.
Example
To activate "maintenance mode" in WordPress, you might need to execute this wp-cli command:
$ wp maintenance-mode activate
Enabling Maintenance mode...
Success: Activated Maintenance mode.
Now, with the Terminal, you can do this straight from your PHP script:
Terminal::run('wp maintenance-mode activate');
More
You can even setup timeout, retries, change the current working directory and much more:
Terminal::in(storage_path('sites/123'))
->timeout(120)
->retries(3)
->run('wp maintenance-mode activate');
Extending
Another cool feature of the Terminal is that you can easily define your custom commands.
Terminal::extend('maintenanceOn', function ($terminal) {
return $terminal->run('wp maintenance-mode activate');
});
Terminal::maintenanceOn();
Testing
It gets even better.
Terminal comes with a bunch of beautiful testing utilities that help you write simple and expressive tests for your application.
Terminal::fake();
Terminal::run($command = 'wp maintenance-mode activate');
Terminal::assertExecuted($command);
Feel free to check out full documentation at https://github.com/TitasGailius/terminal
Feedback is more than welcome!
Posted on March 22, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.