ShellWrap – Beautiful PHP Shell Wrapper

1152

Es un momento emocionante para ser un desarrollador PHP. Hay un montón de librerías útiles liberados todos los días y con la ayuda de composer y Github son fáciles de descubrir y utilizar.

ShellWrap es una libreria que le permite trabajar con las poderosas herramientas de línea de comandos de Linux/Unix en PHP a través de excelente sintaxis:

[php]
require ‘ShellWrap.php’;
use \MrRio\ShellWrap as sh;

// List all files in current dir
echo sh::ls();

// Checkout a branch in git
sh::git(‘checkout’, ‘master’);

// You can also pipe the output of one command, into another
// This downloads example.com through cURL, follows location, then pipes through grep to
// filter for ‘html’
echo sh::grep(‘html’, sh::curl(‘http://example.com’, array(
‘location’ => true
)));

// Touch a file to create it
sh::touch(‘file.html’);

// Remove file
sh::rm(‘file.html’);

// Remove file again (this fails, and throws an exception because the file doesn’t exist)

try {
sh::rm(‘file.html’);
} catch (Exception $e) {
echo ‘Caught failing sh::rm() call’;
}

[/php]

La libreria genera excepciones cuando se produce un error en el comando, para que pueda actuar en consecuencia. También puede canalizar la salida de un comando como la entrada de otro para una flexibilidad aún mayor.