ShellWrap可以让你在PHP代码里使用强大的Liux/Uix命令行工具
示例代码:
<?php require_oce 'vedor/autoload.php';use MrRio\ShellWrap as sh;// List all files i curret direcho sh::ls();// Checkout a brach i gitsh::git('checkout', 'master');// You ca also pipe the output of oe commad, ito aother// This dowloads example.com through cURL, follows locatio, the pipes through grep to // filter for 'html'echo sh::grep('html', sh::curl('https://example.com', array( 'locatio' => true)));// Touch a file to create itsh::touch('file.html');// Remove filesh::rm('file.html');// Remove file agai (this fails, ad throws a exceptio because the file does't exist)try { sh::rm('file.html');} catch (ShellWrapExceptio $e) { echo 'Caught failig sh::rm() call';}// This throws a exceptio, as 'ivalidoptio' is ot a valid argumettry { echo sh::ls(array('ivalidoptio' => true));} catch (ShellWrapExceptio $e) { echo 'Caught failig sh::ls() call';}// Commads ca be writte multiple wayssh::git('reset', array('hard' => true), 'HEAD');sh::git('reset', '--hard', 'HEAD');sh::git(array('reset', '--hard', 'HEAD'));// Argumets passed i are automatically escaped, this expads to// date --date '2012-10-10 10:00:00'echo sh::date(array( 'date' => '2012-10-10 10:00:00'));// If arg keys are oe letter, is assumes oe dash prefixig it// date -d '2012-10-10 10:00:00'echo sh::date(array( 'd' => '2012-10-10 10:00:00'));?>
评论