https://github.com/pastuhov/php-exec-command
Simple php command executor with param binding
https://github.com/pastuhov/php-exec-command
command execute php
Last synced: 9 months ago
JSON representation
Simple php command executor with param binding
- Host: GitHub
- URL: https://github.com/pastuhov/php-exec-command
- Owner: pastuhov
- License: gpl-2.0
- Created: 2015-06-19T13:47:25.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-21T14:37:09.000Z (about 8 years ago)
- Last Synced: 2025-04-30T15:50:02.051Z (9 months ago)
- Topics: command, execute, php
- Language: PHP
- Size: 28.3 KB
- Stars: 25
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-exec-command
[](https://travis-ci.org/pastuhov/php-exec-command)
[](https://scrutinizer-ci.com/g/pastuhov/php-exec-command/?branch=master)
[](https://scrutinizer-ci.com/g/pastuhov/php-exec-command/?branch=master)
[](https://packagist.org/packages/pastuhov/php-exec-command)
[](https://styleci.io/repos/37724184)
Simple php command executor with param binding.
## Install
Via Composer
``` bash
$ composer require pastuhov/php-exec-command
```
## Features
* light weight
* param binding
* throws an exception if return status >0
* redirect stderr to stdout if needed
## Usage
```php
$output = Command::exec(
'echo {phrase}',
[
'phrase' => 'hello'
]
);
// $output = 'hello'
```
or
```php
$output = Command::exec(
'echo {phrase}',
[
'phrase' => [
'hello',
'world'
]
]
);
// $output = 'hello world'
```
or
```php
try {
Command::exec('locate {parody}',
[
'parody' => [
'pink_unicorn'
]
]
);
echo "unicorn was found!";
} catch (\pastuhov\Command\CommandException $e) {
echo "can't find unicorn :(";
}
```
By default, all arguments are escaped using
[escapeshellarg](https://secure.php.net/manual/en/function.escapeshellarg.php).
If you need to pass unescaped arguments, use `{!name!}`, like so:
```php
Command::exec('echo {!path!}', ['path' => '$PATH']);
```
## Testing
``` bash
$ composer test
```
or
```bash
$ phpunit
```
## Security
If you discover any security related issues, please email kirill@pastukhov.su instead of using the issue tracker.
## Credits
- [Kirill Pastukhov](https://github.com/pastuhov)
- [All Contributors](../../contributors)
## License
GNU General Public License, version 2. Please see [License File](LICENSE) for more information.