From 9d00040010e849ebb57b257e3022f854b55884a2 Mon Sep 17 00:00:00 2001 From: Andrey Ryzhov Date: Tue, 8 May 2018 09:30:54 +0300 Subject: [PATCH] Add description and some comments. --- README.md | 17 +++++++++++++++++ src/Functions/FunctionAbstract.php | 4 ++++ src/FunctionsHolder.php | 3 +++ 3 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 681c049..fa388fd 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,23 @@ $instance->one = 'swim'; $instance->replace($string); // equals to 'Gogoriki go swim ``` +`comma` function may get params: `comma(param1, param2)` + +- *param1* set to `1` if you want to miss first comma appearance in string +- *param2* set to `1` if you want to begin new group of words for next missing of first comma appearance in string + +```php +$string = 'I know words: #it:addcomma(1)##and_it:addcomma(1)# and #and_it_2:addcomma(1, 1)#'; +$instance = new PowerReplace(); +$instance->setArray( + 'it' => 'eat', + 'and_it' = 'play', + 'and_it_2' = 'sleep' + ); +$instance->replace($string); // equals to 'I know words: eat, play and sleep' + +``` + ### maxlen Replace marker with value if string behind this one is less then poined in parameter. diff --git a/src/Functions/FunctionAbstract.php b/src/Functions/FunctionAbstract.php index a75b520..bf8888b 100644 --- a/src/Functions/FunctionAbstract.php +++ b/src/Functions/FunctionAbstract.php @@ -17,6 +17,10 @@ abstract class FunctionAbstract { abstract public function __invoke($string); + /** + * Functions can accumulate some values for single string for handle. + * Useful for clear values in function objects. + */ public function clear() { diff --git a/src/FunctionsHolder.php b/src/FunctionsHolder.php index b8fa48a..bd2dd10 100644 --- a/src/FunctionsHolder.php +++ b/src/FunctionsHolder.php @@ -46,6 +46,9 @@ protected function getFunctionWithName($name) } + /** + * Clear accumulated values for all created function instances. + */ public function clear() { foreach ($this->functions as $function) {