PHP code example of titasgailius / terminal
1. Go to this page and download the library: Download titasgailius/terminal library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
titasgailius / terminal example snippets
$response = Terminal::run('rm -rf vendor');
$response->getExitCode() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->lines() : array;
$response->output() : string;
(string) $response: string;
foreach ($response->lines() as $line) {
//
}
foreach ($response as $line) {
//
}
$line->error(); // true|false
(string) $line;
$line->content();
public function handle()
{
Terminal::output($this)->run('echo Hello, World');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
Terminal::output($output)->run('echo Hello, World');
}
$response = Terminal::run(...);
$response->throw();
return (string) $response;
Terminal::runInBackground('rm -rf vendor');
Terminal::inBackground()->run('rm -rf node_modules');
// Do some other stuff...
Terminal::wait();
Terminal::with([
'firstname' => 'John',
'lastname' => 'Doe',
])->run('echo Hello, {{ $firstname}} {{ $lastname }}');
Terminal::with('greeting', 'World')
->run('echo Hello, {{ $greeting }}');
Terminal::in(storage_path('framework'))->run('rm -rf views');
Terminal::timeout(25)->run('rm -rf vendor');
$duration = new DateInterval('PT25S');
Terminal::timeout($duration)->run('rm -rf vendor');
$date = (new DateTime)->add(new DateInterval('PT25S'));
Terminal::timeout($date)->run('rm -rf vendor');
$date = Carbon::now()->addSeconds(25);
Terminal::timeout($date)->run('rm -rf vendor');
Terminal::retries(3, 100)->run('rm -rf vendor');
Terminal::withEnvironmentVariables([
'APP_ENV' => 'testing',
])->run('rm -rf $DIRECTORY');
$command = Terminal::command('rm -rf vendor');
if ($inBackground) {
$command->inBackground();
}
$command->run();
$process = Terminal::timeout(25)->process();
$response = Terminal::run(...);
$process = $response->process();
$response = Terminal::run(...);
$response->isRunning(); // "isRunning" method is passed to the \Symfony\Component\Process\Process class
Terminal::extend('removeVendors', function ($terminal) {
return $terminal->run('rm -rf vendors');
});
Terminal::removeVendors();
Terminal::fake();
$response = Terminal::run(...);
Terminal::fake([
'php artisan inspire' => 'Simplicity is the ultimate sophistication. - Leonardo da Vinci',
'cowsay Hi, How are you' => [
' _________________ ',
'< Hi, How are you > ',
' ----------------- ',
' \ ^__^ ',
' \ (oo)\_______ ',
' (__)\ )\/\ ',
' ||----w | ',
' || || ',
],
]);
Terminal::fake([
'wp cli update' => [
Terminal::line('Downloading WordPress files.'),
Terminal::error('WordPress is down.'),
],
]);
Terminal::fake([
'php artisan migrate' => Terminal::response([
'Migrating: 2012_12_12_000000_create_users_table',
'Migrated: 2012_12_12_000000_create_users_table',
])->shouldFail(),
]);
Terminal::fake();
Terminal::run('php artisan migrate');
Terminal::assertExecuted('php artisan migrate');
Terminal::fake();
Terminal::assertNotExecuted('php artisan migrate');
$process = Mockery::mock(Process::class, function ($mock) {
$mock->shouldReceive('getPid')
->twice()
->andReturn(123, 321);
});
Terminal::fake([
// Empty response with a mocked \Symfony\Component\Process\Process instance.
'factor 12' => Terminal::response($process)
// Response lines with a mocked \Symfony\Component\Process\Process instance.
'php artisan migrate' => Terminal::response([
'Migrating: 2012_12_12_000000_create_users_table',
'Migrated: 2012_12_12_000000_create_users_table',
], $process),
]);
$this->assertEquals(123, Terminal::run('factor 12')->getPid());
$this->assertEquals(321, Terminal::run('php artisan migrate')->getPid());
/**
* This method is called after each test.
*/
protected function tearDown(): void
{
parent::tearDown();
Terminal::reset();
}