pastuhov / php-exec-command
简单的PHP命令执行器,支持参数绑定。
1.1.0
2016-08-27 09:07 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
This package is not auto-updated.
Last update: 2024-09-14 18:04:08 UTC
README
简单的PHP命令执行器,支持参数绑定。
安装
通过Composer
$ composer require pastuhov/php-exec-command
功能
- 轻量级
- 参数绑定
- 如果返回状态 >0 则抛出异常
- 如果需要,将标准错误重定向到标准输出
用法
$output = Command::exec( 'echo {phrase}', [ 'phrase' => 'hello' ] ); // $output = 'hello'
或
$output = Command::exec( 'echo {phrase}', [ 'phrase' => [ 'hello', 'world' ] ] ); // $output = 'hello world'
或
try { Command::exec('locate {parody}', [ 'parody' => [ 'pink_unicorn' ] ] ); echo "unicorn was found!"; } catch (\pastuhov\Command\CommandException $e) { echo "can't find unicorn :("; }
默认情况下,所有参数都使用escapeshellarg进行转义。如果您需要传递未转义的参数,请使用{!name!}
,例如
Command::exec('echo {!path!}', ['path' => '$PATH']);
测试
$ composer test
或
$ phpunit
安全
如果您发现任何与安全相关的问题,请通过kirill@pastukhov.su发送电子邮件,而不是使用问题跟踪器。
致谢
许可协议
GNU通用公共许可证,版本2。有关更多信息,请参阅许可文件。