PHP code example of netson / l4shell

1. Go to this page and download the library: Download netson/l4shell 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/ */

    

netson / l4shell example snippets


// app/config/app.php
'providers' => array(
	...
	'Netson\L4shell\L4shellServiceProvider',
);

'L4shell' => 'Netson\L4shell\Facades\Command'

$command = L4shell::get();

$command = new \Netson\L4shell\Command("command", array("arg1", "arg2"));

$command = L4shell::get();
$result = $command->setCommand('hostname')->execute();

$command = L4shell::get();
$result = $command->setCommand('hostname %s')->setArguments(array("-s"))->execute();

$command = L4shell::get();
$command->setCommand('ls %s %s')->setArguments(array("-a"));
// do something else ...
$command->setArguments(array("-l"), true); // add the optional second argument to keep existing arguments
$result = $command->execute();

$command = L4shell::get();
$command->clearArguments();

$command = L4shell::get();
$result = $command->setCommand("hostname")->sendToDevNull()->execute(); // will return exit code (0), but no output message

$command = L4shell::get();
$result = $command->setLogging(true)->setCommand("hostname")->execute();

$command = L4shell::get();
$result = $command->setExecutionPath("/path/to/your/folder")->setCommand("ls")->execute();

$command = L4shell::get();
$result = $command->setExecutionPath()->setCommand("ls")->execute();

$command = L4shell::get();
$result = $command->setExecutablePath("/usr/bin")->setCommand("ls")->execute();

$command = L4shell::get();
$result = $command->setExecutablePath()->setCommand("ls")->execute();

$command = L4shell::setCommand('find ./ -maxdepth 1 -name %s')->setArguments(array("*.txt"))->setAllowedCharacters(array("*"));
// returned with allowed characters: find ./ -maxdepth 1 -name '*.txt'
// returned without allowed characters: find ./ -maxdepth 1 -name '\*.txt'

public function testSomething ()
{
    L4shell::shouldReceive('get')->once();
    L4shell::shouldReceive('execute')->once()->andReturn("your message");
}
public function tearDown ()
{
    \Mockery::close();
}
$ php composer.phar 
$ php artisan config:publish netson/l4shell
app/config/packages/netson/l4shell/config.php