From 734bb3f671b8d1ab4d9cc214fb477b1eb7bd61e2 Mon Sep 17 00:00:00 2001 From: Krzysztof Born Date: Thu, 8 Sep 2016 15:26:22 +0200 Subject: [PATCH 1/2] Add possibility to specify the flow of creating operation arguments --- README.md | 3 +++ src/Command.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02e9354..76723e0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Command.php b/src/Command.php index 7bfefe9..42d8b84 100644 --- a/src/Command.php +++ b/src/Command.php @@ -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 { From 695ee26ab998046f0fbeaa2c6f6b9c2770184bbc Mon Sep 17 00:00:00 2001 From: Krzysztof Born Date: Mon, 19 Jun 2017 13:14:50 +0200 Subject: [PATCH 2/2] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d7eee2f..d4b179d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ phpunit.xml composer.lock /vendor/ *.swp +/nbproject/private/ \ No newline at end of file