Beispiel #1
0
<?php

/**
 * Interactively create a text file and then delete it by typing 'y' at the command line interface. Here we will start
 * executing commands right away and use callbacks to interactively respond to the prompts.
 *
 */
require '../vendor/autoload.php';
include '../src/Steveorevo/VirtualCLI/VirtualCLI.php';
use Steveorevo\VirtualCLI\VCLIManager;
use Steveorevo\VirtualCLI\VirtualCLI;
// Create a new virtual command line interface named "test" (or access an existing one by that name)
VCLIManager::init();
$myVCLI = new VirtualCLI("test");
// Start processing commands as we interactively add them
$myVCLI->start();
// Echo 'hello world' to a file in the current directory
$myVCLI->add_command('echo Hello World > test.txt');
// Remove the file interactively using del or rm and by waiting for the Y/n prompt
if (VCLIManager::$platform === 'win32') {
    $command = 'del /P test.txt';
    // /P for prompt flag on Windows
} else {
    $command = 'rm -i test.txt';
    // -i for interactive mode on *nix
}
// Wait for the question mark to appear and invoke the callback
$myVCLI->add_command($command, '?', function ($results) use($myVCLI) {
    // Send a Y for 'yes' and pause a second
    $myVCLI->add_command('Y', 1);
});
 */
require '../vendor/autoload.php';
include '../src/Steveorevo/VirtualCLI/VirtualCLI.php';
use Steveorevo\VirtualCLI\VCLIManager;
use Steveorevo\VirtualCLI\VirtualCLI;
// Determine the shell runtime via DS-CLI's boot script for the given platform
VCLIManager::init();
if (VCLIManager::$platform === 'win32') {
    $shell = '"c:\\xampplite\\ds-plugins\\ds-cli\\platform\\win32\\boot.bat" bash.exe --posix -i';
    $wait = 0;
} else {
    $shell = "/Applications/XAMPP/ds-plugins/ds-cli/platform/mac/boot.sh bash";
    $wait = "bash";
}
// Create a new virtual command line interface running bash with a 5 minute timeout
$myVCLI = new VirtualCLI("ds-cli-example", 5 * 60, $shell, $wait, ";");
// Change directories to the home folder
$myVCLI->add_command("ls -la");
// Change directories to the home folder
$myVCLI->add_command("cd ~");
// Remove any prior wordpress folder and latest.zip file
$myVCLI->add_command("rm latest.zip;rm -rf wordpress");
// Download the latest copy of WordPress
$myVCLI->add_command("wget https://wordpress.org/latest.zip");
// Unzip it
$myVCLI->add_command("unzip -q latest.zip");
// LFTP into our host's site, wait 5 seconds to connect
$myVCLI->add_command("lftp ftp://spress-deploy:J3NeM4yx@deploy.postmy.info/web --debug 5", 5);
// Remove prior wordpress folder, recreate it, cd into it, and wait for 'cd ok' confirmation
$myVCLI->add_command("rm -rf wordpress;mkdir wordpress;cd wordpress");
// Change local directory to our unzipped home folder / wordpress and wait for 'lcd ok' confirmation
Beispiel #3
0
<?php

/**
 * Open a virtual command line, get the current directory listing, then close command line. It's best practice to close
 * the terminal when we don't need it anymore otherwise it will persist in memory. We later shutdown the vcli daemon
 * (use wisely as this will close down all the terminals, regardless of who created them or if we forgot to close 'em).
 *
 */
require '../vendor/autoload.php';
include '../src/Steveorevo/VirtualCLI/VirtualCLI.php';
use Steveorevo\VirtualCLI\VCLIManager;
use Steveorevo\VirtualCLI\VirtualCLI;
// Create a new virtual command line interface named "test" (or continue accessing an existing one of that name)
VCLIManager::init();
$myVCLI = new VirtualCLI("test");
// Queue typing 'ls' or 'dir' (Windows) on the command line
if (VCLIManager::$platform === 'win32') {
    $myVCLI->add_command('dir');
} else {
    $myVCLI->add_command('ls');
}
// List any existing consoles
var_dump(VCLIManager::cli_list(2));
// Start processing commands in queue
$myVCLI->start();
// Wait until the queue is done
while (false === $myVCLI->is_done()) {
    usleep(1000);
    // Wait a second
}
// Echo out the console history