From 41ada86392a9930e53c90c207b967f623297954c Mon Sep 17 00:00:00 2001 From: Crisciany Silva Date: Tue, 27 Feb 2024 12:14:36 -0400 Subject: [PATCH] fix argument in function to speak Signed-off-by: Crisciany Silva --- src/Espeak.php | 4 +++- src/InputOptions.php | 11 ++--------- src/QuoteStringTrait.php | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/QuoteStringTrait.php diff --git a/src/Espeak.php b/src/Espeak.php index 56f6378..f5a0a00 100644 --- a/src/Espeak.php +++ b/src/Espeak.php @@ -6,6 +6,8 @@ class Espeak { + use QuoteStringTrait; + private InputOptions $inputOptions; public function __construct() { @@ -34,7 +36,7 @@ public function execute(string $argument = ''): string } $cmd = 'espeak-ng' . $options; if (strlen($argument) > 0) { - $cmd .= ' ' . $argument; + $cmd .= ' ' . $this->quoteString($argument); } $output = \shell_exec($cmd); return $output; diff --git a/src/InputOptions.php b/src/InputOptions.php index 4e94631..4fc43e9 100644 --- a/src/InputOptions.php +++ b/src/InputOptions.php @@ -6,6 +6,8 @@ class InputOptions implements Stringable { + use QuoteStringTrait; + private array $options = []; public function setOption(string $name, ?string $value = null) { @@ -17,15 +19,6 @@ public function hasOption(string $name) return array_key_exists($name, $this->options); } - private function quoteString(string $value): string - { - $value = str_replace('"', '\"', $value); - if (str_contains($value, ' ')) { - $value = '"' . $value . '"'; - } - return $value; - } - private function nameValueToString(string $name, array $values, string $separator, string $type) { $return = []; diff --git a/src/QuoteStringTrait.php b/src/QuoteStringTrait.php new file mode 100644 index 0000000..c7c0bf5 --- /dev/null +++ b/src/QuoteStringTrait.php @@ -0,0 +1,15 @@ +