Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to specify the flow of creating operation arguments #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ phpunit.xml
composer.lock
/vendor/
*.swp
/nbproject/private/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pass `command`, `execCommand` and `args` as options. This will call the respecti
* `$value`: The optional argument value which will get escaped if `$escapeArgs` is true.
An array can be passed to add more than one value for a key, e.g. `addArg('--exclude', array('val1','val2'))`
which will create the option "--exclude 'val1' 'val2'".
Value inside that array can be array itself too. In that case it should have structure like this:
//structure of $v = [argument, value, separator, escape]. For example ['to_page', 2, ' ', false].
Then the construction of command line argument will use its privately defined flow.
* `$escape`: If set, this overrides the `$escapeArgs` setting and enforces escaping/no escaping
* `getOutput()`: The command output as string. Empty if none.
* `getError()`: The error message, either stderr or internal message. Empty if no error.
Expand Down
12 changes: 11 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,17 @@ public function addArg($key, $value = null, $escape = null)
if (is_array($value)) {
$params = array();
foreach ($value as $v) {
$params[] = $doEscape ? escapeshellarg($v) : $v;
//when operation argument is an array, then use its private escape flag for it
if (is_array($v)) {
//structure of $v = [argument, value, separator, escape]
if ($v[3] !== null) {
$params[] = $v[3] ? escapeshellarg($v[0].$v[2].$v[1]) : $v[0].$v[2].$v[1];
} else {
$params[] = $doEscape ? escapeshellarg($v[0].$v[2].$v[1]) : $v[0].$v[2].$v[1];
}
} else {
$params[] = $doEscape ? escapeshellarg($v) : $v;
}
}
$this->_args[] = $key.$separator.implode(' ',$params);
} else {
Expand Down