From 24d3c17bcb3d44b2b2c128328acd34ff64de61f6 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sun, 25 Apr 2021 10:37:45 +0300 Subject: [PATCH 1/4] =?UTF-8?q?+=20README=20=E2=86=92=20Documentation=20?= =?UTF-8?q?=E2=86=92=20Parameters=20description=20=E2=86=92=20`\ddTools::p?= =?UTF-8?q?arseText($params)`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++ modx.ddtools.class.php | 13 +-------- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9d87791..5c3430f 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,70 @@ _ddTools version must be 0.14 or higher to use this method. If you use it, the c ### Parameters description +#### `\ddTools::parseText($params)` + +Replaces placeholders in a text with required values. +Like `$modx->parseChunk`, but takes a text and has some features. + +* `$params` + * Desctription: Parameters, the pass-by-name style is used. + * Valid values: + * `stdClass` + * `arrayAssociative` + * **Required** + +* `$params->text` + * Desctription: String to parse. + * Valid values: `string` + * **Required** + +* `$params->data` + * Desctription: + The array of additional data has to be replaced in `$params->text`. + Nested objects and arrays are supported too: + * `{"someOne": "1", "someTwo": "test" }` => `[+someOne+], [+someTwo+]`. + * `{"some": {"a": "one", "b": "two"} }` => `[+some.a+]`, `[+some.b+]`. + * `{"some": ["one", "two"] }` => `[+some.0+]`, `[+some.1+]`. + * Valid values: + * `arrayAssociative` + * `stdClass` + * Default value: `[]` + +* `$params->data->{$key}` + * Valid values: Key is placeholder name, value is value. + * `string` + * `arrayAssociative` + * `stdClass` + * **Required** + +* `$params->placeholderPrefix` + * Desctription: Placeholders prefix. + * Valid values: `string` + * Default value: `'[+'` + +* `$params->placeholderSuffix` + * Desctription: Placeholders suffix. + * Valid values: `string` + * Default value: `'+]'` + +* `$params->removeEmptyPlaceholders` + * Desctription: Do you need to remove empty placeholders? + * Valid values: `boolean` + * Default value: `false` + +* `$params->mergeAll` + * Desctription: Additional parsing of document fields, settings, chunks. + * Valid values: `boolean` + * Default value: `true` + + +##### Returns + +* `$result` + * Desctription: Parsed text. + * Valid values: `string` + + #### `\ddTools::verifyRenamedParams($params)` The method checks an array for deprecated parameters and writes warning messages into the MODX event log. diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 2d03b7e..2b7a87a 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -899,18 +899,7 @@ public static function logEvent($params){ * parseText * @version 1.5.2 (2019-06-22) * - * @desc Similar to $modx->parseChunk, but takes a text. - * - * @param $params {stdClass|arrayAssociative} — Parameters, the pass-by-name style is used. @required - * @param $params->text {string} — String to parse. @required - * @param $params->data {stdClass|arrayAssociative} — Array of values. Nested arrays are supported too: “['stringPlaceholder' = > 'one', 'arrayPlaceholder' => ['a' => 'one', 'b' => 'two']]” => “[+stringPlaceholder+]”, “[+arrayPlaceholder.a+]”, “[+arrayPlaceholder.b+]”. Default: []. - * @param $params->data->{$key} {string|stdClass|arrayAssociative} — Key — placeholder name, value — value. - * @param $params->placeholderPrefix {string} — Placeholders prefix. Default: '[+'. - * @param $params->placeholderSuffix {string} — Placeholders suffix. Default: '+]'. - * @param $params->removeEmptyPlaceholders {boolean} — Do you need to remove empty placeholders? Default: false. - * @param $params->mergeAll {boolean} — Additional parsing the document fields, settings, chunks. Default: true. - * - * @return {string} + * @see README.md */ public static function parseText($params = []){ //For backward compatibility From 3e9ffa49ce756eaf1b40ff786aed74e18b9c5311 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sun, 25 Apr 2021 10:42:00 +0300 Subject: [PATCH 2/4] * `\ddTools::parseText`: `\DDTools\ObjectTools::extend` is used instead of `array_merge`. --- modx.ddtools.class.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 2b7a87a..3c838f1 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -897,7 +897,7 @@ public static function logEvent($params){ /** * parseText - * @version 1.5.2 (2019-06-22) + * @version 1.5.3 (2021-04-25) * * @see README.md */ @@ -917,18 +917,21 @@ public static function parseText($params = []){ ]); } - //Defaults - $params = (object) array_merge( - [ - 'text' => '', - 'data' => [], - 'placeholderPrefix' => '[+', - 'placeholderSuffix' => '+]', - 'removeEmptyPlaceholders' => false, - 'mergeAll' => true - ], - (array) $params - ); + $params = \DDTools\ObjectTools::extend([ + 'objects' => [ + //Defaults + (object) [ + 'text' => '', + 'data' => [], + 'placeholderPrefix' => '[+', + 'placeholderSuffix' => '+]', + 'removeEmptyPlaceholders' => false, + 'mergeAll' => true + ], + $params + ] + ]); + $result = $params->text; From 460736cf36b339085e195a14043267fd9f89f958 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sun, 25 Apr 2021 10:47:47 +0300 Subject: [PATCH 3/4] =?UTF-8?q?+=20`\ddTools::parseText`=20=E2=86=92=20Par?= =?UTF-8?q?ameters=20=E2=86=92=20`$params->data`:=20Can=20also=20be=20set?= =?UTF-8?q?=20as=20JSON,=20HJSON=20or=20Query=20string.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++-- modx.ddtools.class.php | 12 ++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5c3430f..9db2156 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,16 @@ Like `$modx->parseChunk`, but takes a text and has some features. * Valid values: * `arrayAssociative` * `stdClass` + * `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON) + * `stringHjsonObject` — as [HJSON](https://hjson.github.io/) + * `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string) * Default value: `[]` * `$params->data->{$key}` * Valid values: Key is placeholder name, value is value. * `string` - * `arrayAssociative` - * `stdClass` + * `array` + * `object` * **Required** * `$params->placeholderPrefix` diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 3c838f1..54d70f7 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -897,7 +897,7 @@ public static function logEvent($params){ /** * parseText - * @version 1.5.3 (2021-04-25) + * @version 1.6 (2021-04-25) * * @see README.md */ @@ -932,13 +932,13 @@ public static function parseText($params = []){ ] ]); + $params->data = \DDTools\ObjectTools::convertType([ + 'object' => $params->data, + 'type' => 'objectArray' + ]); - $result = $params->text; - //Convert stdClass to array - if (!is_array($params->data)){ - $params->data = (array) $params->data; - } + $result = $params->text; //Если значения для парсинга переданы if (!empty($params->data)){ From 8e5bd0d4d92971aa8a4503aeb251382fbea6fed5 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sun, 25 Apr 2021 12:36:46 +0300 Subject: [PATCH 4/4] Prerelease --- CHANGELOG.md | 7 +++++++ CHANGELOG_ru.md | 7 +++++++ composer.json | 2 +- modx.ddtools.class.php | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9733049..9277dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # (MODX)EvolutionCMS.libraries.ddTools changelog +## Version 0.49 (2021-04-25) +* \* `\ddTools::parseText`: + * \+ Parameters → `$params->data`: Can also be set as JSON, HJSON or Query string. + * \* `\DDTools\ObjectTools::extend` is used instead of `array_merge`. +* \+ README → Documentation → Parameters description → `\ddTools::parseText($params)`. + + ## Version 0.48.2 (2021-03-31) * \* `\DDTools\ObjectTools::extend`: Added deep object cloning to prevent references. diff --git a/CHANGELOG_ru.md b/CHANGELOG_ru.md index c768a6e..9d282ff 100644 --- a/CHANGELOG_ru.md +++ b/CHANGELOG_ru.md @@ -1,6 +1,13 @@ # (MODX)EvolutionCMS.libraries.ddTools changelog +## Версия 0.49 (2021-04-25) +* \* `\ddTools::parseText`: + * \+ Параметры → `$params->data`: Также может быть задан как JSON, HJSON или Query string. + * \* `\DDTools\ObjectTools::extend` исползуется вместо `array_merge`. +* \+ README → Документация → Описание параметров → `\ddTools::parseText($params)`. + + ## Версия 0.48.2 (2021-03-31) * \* `\DDTools\ObjectTools::extend`: Добавлено глубокое клонирование объектов для предотвращения ссылок. diff --git a/composer.json b/composer.json index b6b448b..89bbb8d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dd/evolutioncms-libraries-ddtools", "type": "modxevo-library-ddtools", - "version": "0.48.2", + "version": "0.49.0", "description": "A library with various tools facilitating your work.", "keywords": [ "modx", diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 54d70f7..8afe130 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1,7 +1,7 @@