From 952d2da9f9075c00055be0ed1ed250f52351d35f Mon Sep 17 00:00:00 2001 From: neveldo Date: Wed, 11 Mar 2020 12:17:32 +0100 Subject: [PATCH] Other text functions now returns '[empty]' instead of '' --- CHANGELOG.md | 5 ++++- src/TextGenerator/TextFunction/ChooseFunction.php | 5 +++-- src/TextGenerator/TextFunction/CoalesceFunction.php | 12 ++---------- src/TextGenerator/TextFunction/FilterFunction.php | 10 ++++++++-- src/TextGenerator/TextFunction/IfFunction.php | 3 ++- src/TextGenerator/TextFunction/LoopFunction.php | 3 ++- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc44fdb..9f00ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # ChangeLog Change log for TextGenerator +## 1.6.0 - February 11, 2020 +- Other text functions now returns '[empty]' instead of '' + ## 1.5.0 - February 11, 2020 -- ProbabilityRandomFunction and RandomFunction now returns '[empty]'' instead of '' if there is no valid choices as arguments. +- ProbabilityRandomFunction and RandomFunction now returns '[empty]' instead of '' if there is no valid choices as arguments. ## 1.4.0 - February 11, 2020 - ExprFunction now returns [empty] if the expression thrown an Error or an Exception. diff --git a/src/TextGenerator/TextFunction/ChooseFunction.php b/src/TextGenerator/TextFunction/ChooseFunction.php index 20850d9..a06d318 100644 --- a/src/TextGenerator/TextFunction/ChooseFunction.php +++ b/src/TextGenerator/TextFunction/ChooseFunction.php @@ -2,13 +2,14 @@ namespace Neveldo\TextGenerator\TextFunction; +use Neveldo\TextGenerator\Tag\TagReplacer; use Neveldo\TextGenerator\Tag\TagReplacerInterface; /** * Class ChooseFunction * 'choose' function : returns one item from the function arguments * Examples : - * #random{2|one|two|three} will output 'two' + * #choose{2|one|two|three} will output 'two' * * @package Neveldo\TextGenerator\TextFunction */ @@ -51,7 +52,7 @@ public function execute(array $arguments, array $originalArguments) return $arguments[$index]; } - return ''; + return TagReplacer::EMPTY_TAG; } } \ No newline at end of file diff --git a/src/TextGenerator/TextFunction/CoalesceFunction.php b/src/TextGenerator/TextFunction/CoalesceFunction.php index 134343b..0cad68e 100644 --- a/src/TextGenerator/TextFunction/CoalesceFunction.php +++ b/src/TextGenerator/TextFunction/CoalesceFunction.php @@ -2,17 +2,9 @@ namespace Neveldo\TextGenerator\TextFunction; +use Neveldo\TextGenerator\Tag\TagReplacer; use Neveldo\TextGenerator\Tag\TagReplacerInterface; -/** - * Class ChooseFunction - * 'choose' function : returns one item from the function arguments - * Examples : - * #random{2|one|two|three} will output 'two' - * - * @package Neveldo\TextGenerator\TextFunction - */ - /** * Class CoalesceFunction * 'coalesce' function : return the first non empty argument @@ -51,7 +43,7 @@ public function execute(array $arguments, array $originalArguments) } } - return ''; + return TagReplacer::EMPTY_TAG; } } \ No newline at end of file diff --git a/src/TextGenerator/TextFunction/FilterFunction.php b/src/TextGenerator/TextFunction/FilterFunction.php index d6990a5..e295a8e 100644 --- a/src/TextGenerator/TextFunction/FilterFunction.php +++ b/src/TextGenerator/TextFunction/FilterFunction.php @@ -2,6 +2,7 @@ namespace Neveldo\TextGenerator\TextFunction; +use Neveldo\TextGenerator\Tag\TagReplacer; use Neveldo\TextGenerator\Tag\TagReplacerInterface; /** @@ -190,9 +191,14 @@ public function execute(array $arguments, array $originalArguments) } if (is_callable($filter['function'])) { - return call_user_func_array($filter['function'], $arguments); + try { + return call_user_func_array($filter['function'], $arguments); + } catch (\Exception $e) { + return TagReplacer::EMPTY_TAG; + } } - return ''; + + return TagReplacer::EMPTY_TAG; } /** diff --git a/src/TextGenerator/TextFunction/IfFunction.php b/src/TextGenerator/TextFunction/IfFunction.php index 84ba13a..42ff6f1 100644 --- a/src/TextGenerator/TextFunction/IfFunction.php +++ b/src/TextGenerator/TextFunction/IfFunction.php @@ -2,6 +2,7 @@ namespace Neveldo\TextGenerator\TextFunction; +use Neveldo\TextGenerator\Tag\TagReplacer; use Neveldo\TextGenerator\Tag\TagReplacerInterface; use Neveldo\TextGenerator\ExpressionLanguage\ExpressionLanguage; @@ -57,7 +58,7 @@ public function execute(array $arguments, array $originalArguments) } else if (isset($arguments[2])) { return $arguments[2]; } - return ''; + return TagReplacer::EMPTY_TAG; } } \ No newline at end of file diff --git a/src/TextGenerator/TextFunction/LoopFunction.php b/src/TextGenerator/TextFunction/LoopFunction.php index da6e9a4..56e3060 100644 --- a/src/TextGenerator/TextFunction/LoopFunction.php +++ b/src/TextGenerator/TextFunction/LoopFunction.php @@ -2,6 +2,7 @@ namespace Neveldo\TextGenerator\TextFunction; +use Neveldo\TextGenerator\Tag\TagReplacer; use Neveldo\TextGenerator\Tag\TagReplacerInterface; /** @@ -54,7 +55,7 @@ public function execute(array $arguments, array $originalArguments) // Parse argument 0 : the tag that contain the data to loop on $loopData = $this->tagReplacer->getTag($originalArguments[0]); if (!is_array($loopData)) { - return ''; + return TagReplacer::EMPTY_TAG; } $loopStrings = [];