Skip to content

Commit 888841c

Browse files
committed
Version 0.7
2 parents 1dc2c0f + 990cc02 commit 888841c

7 files changed

Lines changed: 103 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog
22

33

4+
## Version 0.7 (2023-03-30)
5+
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.57 is required.
6+
* \+ Parameters → `getPropValue`: You can now get the value of an object property or an array element in any nesting level. Just use `.` to get nested properties (see `\DDTools\ObjectTools::getPropValue` for more info).
7+
* \* Parameters → `outputter` → Valid values:
8+
* \+ The snippet can also return object as a native PHP object or array (it is convenient to call through `\DDTools\Snippet`). The following new values:
9+
* \* `'objectAuto'`.
10+
* \* `'objectStdClass'`.
11+
* \* `'objectArray'`.
12+
* \* The foillowing have been changed (with backward compatibility):
13+
* \* `'jsonAuto'` → `'stringJsonAuto'`.
14+
* \* `'jsonObject'` → `'stringJsonObject'`.
15+
* \* `'jsonArray'` → `'stringJsonArray'`.
16+
* \* `'queryFormated'` → `'stringQueryFormatted'`.
17+
18+
419
## Version 0.6 (2023-03-08)
520
* \+ Parameters → `extend->objects`: Can also be set as [JSON](https://en.wikipedia.org/wiki/JSON), [HJSON](https://hjson.github.io/) or [Query string](https://en.wikipedia.org/wiki/Query_string).
621

@@ -26,7 +41,7 @@
2641

2742
## Version 0.3 (2020-06-03)
2843
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.38.1 is required.
29-
* \+ Parameters → `sourceObject`, `extend`: Can also be set as `stringQueryFormated`.
44+
* \+ Parameters → `sourceObject`, `extend`: Can also be set as `stringQueryFormatted`.
3045
* \* Refactoring.
3146
* \* README:
3247
* \- Home page.

CHANGELOG_ru.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog
22

33

4+
## Версия 0.7 (2023-03-30)
5+
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.57.
6+
* \+ Параметры → `getPropValue`: Теперь сниппет умеет получать значение свойства объекта или элемента массива на любом уровне вложенности. Просто используйте '.' в параметре для получения свойств вложенных элементов (больше информации см. `\DDTools\ObjectTools::getPropValue`).
7+
* \* Параметры → `outputter` → Допустимые значения:
8+
* \+ Сниппет теперь также умеет возвращать объект в виде нативного PHP объекта или массива (удобно при вызове через `\DDTools\Snippet`). Новые значения:
9+
* \* `'objectAuto'`.
10+
* \* `'objectStdClass'`.
11+
* \* `'objectArray'`.
12+
* \* Следующие допустимые значения изменены (с обратной совместимостью):
13+
* \* `'jsonAuto'` → `'stringJsonAuto'`.
14+
* \* `'jsonObject'` → `'stringJsonObject'`.
15+
* \* `'jsonArray'` → `'stringJsonArray'`.
16+
* \* `'queryFormated'` → `'stringQueryFormatted'`.
17+
18+
419
## Версия 0.6 (2023-03-08)
520
* \+ Параметры → `extend->objects`: Также может быть задан, как [JSON](https://ru.wikipedia.org/wiki/JSON), [HJSON](https://hjson.github.io/) или [Query string](https://en.wikipedia.org/wiki/Query_string).
621

@@ -26,7 +41,7 @@
2641

2742
## Версия 0.3 (2020-06-03)
2843
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.38.1.
29-
* \+ Параметры → `sourceObject`, `extend`: Также может задаваться как `stringQueryFormated`.
44+
* \+ Параметры → `sourceObject`, `extend`: Также может задаваться как `stringQueryFormatted`.
3045
* \* Рефакторинг.
3146
* \* README:
3247
* \- Home page.

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Tools for modifying objects.
77

88
* PHP >= 5.6
99
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
10-
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.51
10+
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.57
1111

1212

1313

@@ -20,7 +20,7 @@ Tools for modifying objects.
2020
#### 1. Elements → Snippets: Create a new snippet with the following data
2121

2222
1. Snippet name: `ddObjectTools`.
23-
2. Description: `<b>0.6</b> Tools for modifying objects.`.
23+
2. Description: `<b>0.7</b> Tools for modifying objects.`.
2424
3. Category: `Core`.
2525
4. Parse DocBlock: `no`.
2626
5. Snippet code (php): Insert content of the `ddObjectTools_snippet.php` file from the archive.
@@ -63,7 +63,7 @@ require_once(
6363
* `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
6464
* `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
6565
* `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
66-
* `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
66+
* `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
6767
* It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
6868
* `array`
6969
* `object`
@@ -74,7 +74,7 @@ require_once(
7474
* Valid values:
7575
* `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
7676
* `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
77-
* `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
77+
* `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
7878
* It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
7979
* `arrayAssociative`
8080
* `object`
@@ -86,7 +86,7 @@ require_once(
8686
* `array`
8787
* `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
8888
* `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
89-
* `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
89+
* `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
9090
* **Required**
9191

9292
* `extend->objects[i]`
@@ -112,19 +112,25 @@ require_once(
112112
* Default value: `true`
113113

114114
* `getPropValue`
115-
* Desctription: Object property name or array index / key to return.
115+
* Desctription: Object property name or array index / key to return.
116+
You can also use `'.'` to get nested properties (see `\DDTools\ObjectTools::getPropValue` for more info).
116117
* Valid values: `string`
117118
* Default value: —
118119

119120
* `outputter`
120121
* Desctription: Output format (when result is an object or array).
121-
Values are case insensitive (the following values are equal: `'jsonauto'`, `'JsonAuto'`, `'JSONAUTO'`, etc).
122+
Values are case insensitive (the following values are equal: `'stringjsonauto'`, `'stringJsonAuto'`, `'STRINGJSONAUTO'`, etc).
122123
* Valid values:
123-
* `'jsonAuto'` — `jsonObject` or `jsonArray` depends on result object
124-
* `'jsonObject'`
125-
* `'jsonArray'`
126-
* `'queryFormated'` — [Query string](https://en.wikipedia.org/wiki/Query_string)
127-
* Default value: `'jsonAuto'`
124+
* The snippet can return object as string:
125+
* `'stringJsonAuto'` — `stringJsonObject` or `stringJsonArray` depends on result object
126+
* `'stringJsonObject'`
127+
* `'stringJsonArray'`
128+
* `'stringQueryFormatted'` — [Query string](https://en.wikipedia.org/wiki/Query_string)
129+
* The snippet can also return object as a native PHP object or array (it is convenient to call through `\DDTools\Snippet`).
130+
* `'objectAuto'` — `stdClass` or `array` depends on result object
131+
* `'objectStdClass'` — `stdClass`
132+
* `'objectArray'` — `array`
133+
* Default value: `'stringJsonAuto'`
128134

129135

130136
## Examples

README_ru.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
* PHP >= 5.6
99
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
10-
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) >= 0.51
10+
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) >= 0.57
1111

1212

1313
## Документация
@@ -22,7 +22,7 @@
2222
##### 1. Элементы → Сниппеты: Создайте новый сниппет со следующими параметрами
2323

2424
1. Название сниппета: `ddObjectTools`.
25-
2. Описание: `<b>0.6</b> Tools for modifying objects.`.
25+
2. Описание: `<b>0.7</b> Tools for modifying objects.`.
2626
3. Категория: `Core`.
2727
4. Анализировать DocBlock: `no`.
2828
5. Код сниппета (php): Вставьте содержимое файла `ddObjectTools_snippet.php` из архива.
@@ -65,7 +65,7 @@ require_once(
6565
* `stringJsonArray` — в виде [JSON](https://ru.wikipedia.org/wiki/JSON)
6666
* `stringHjsonObject` — в виде [HJSON](https://hjson.github.io/)
6767
* `stringHjsonArray` — в виде [HJSON](https://hjson.github.io/)
68-
* `stringQueryFormated` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
68+
* `stringQueryFormatted` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
6969
* Также может быть задан, как нативный PHP объект или массив (например, для вызовов через `$modx->runSnippet`).
7070
* `array`
7171
* `object`
@@ -76,7 +76,7 @@ require_once(
7676
* Допустимые значения:
7777
* `stringJsonObject` — в виде [JSON](https://ru.wikipedia.org/wiki/JSON)
7878
* `stringHjsonObject` — в виде [HJSON](https://hjson.github.io/)
79-
* `stringQueryFormated` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
79+
* `stringQueryFormatted` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
8080
* Также может быть задан, как нативный PHP объект или массив (например, для вызовов через `$modx->runSnippet`).
8181
* `arrayAssociative`
8282
* `object`
@@ -88,7 +88,7 @@ require_once(
8888
* `array`
8989
* `stringJsonArray` — в виде [JSON](https://ru.wikipedia.org/wiki/JSON)
9090
* `stringHjsonArray` — в виде [HJSON](https://hjson.github.io/)
91-
* `stringQueryFormated` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
91+
* `stringQueryFormatted` — в виде [Query string](https://en.wikipedia.org/wiki/Query_string)
9292
* **Обязателен**
9393

9494
* `extend->objects[i]`
@@ -114,19 +114,25 @@ require_once(
114114
* Значение по умолчанию: `true`
115115

116116
* `getPropValue`
117-
* Описание: Возврат значения поля объекта или элемента массива по имени свойства объекта или индексу / ключу массива.
117+
* Описание: Возврат значения поля объекта или элемента массива по имени свойства объекта или индексу / ключу массива.
118+
Вы также можете использовать `'.'` для получения вложенных свойств (больше информации см. `\DDTools\ObjectTools::getPropValue`).
118119
* Допустимые значения: `string`
119120
* Значение по умолчанию: —
120121

121122
* `outputter`
122123
* Описание: Формат вывода (когда результат является объектом или массивом).
123-
Значения регистронезависимы (следующие значения равны: `jsonauto`, `JsonAuto`, `JSONAUTO` и т. п.).
124+
Значения регистронезависимы (следующие значения равны: `stringjsonauto`, `stringJsonAuto`, `STRINGJSONAUTO` и т. п.).
124125
* Допустимые значения:
125-
* `'jsonAuto'` — автоматиески будет выбран `jsonObject` или `jsonArray`, в зависимости от результата
126-
* `'jsonObject'`
127-
* `'jsonArray'`
128-
* `'queryFormated'` — [Query string](https://ru.wikipedia.org/wiki/Query_string)
129-
* Значение по умолчанию: `'jsonAuto'`
126+
* Сниппет умеет возвращать объект в виде строки:
127+
* `'stringJsonAuto'` — автоматиески будет выбран `stringJsonObject` или `stringJsonArray`, в зависимости от результата
128+
* `'stringJsonObject'`
129+
* `'stringJsonArray'`
130+
* `'stringQueryFormatted'` — [Query string](https://ru.wikipedia.org/wiki/Query_string)
131+
* Сниппет также умеет возвращать объект в виде нативного PHP объекта или массива (удобно при вызове через `\DDTools\Snippet`):
132+
* `'objectAuto'` — `stdClass` или `array` в зависимости от результата
133+
* `'objectStdClass'` — `stdClass`
134+
* `'objectArray'` — `array`
135+
* Значение по умолчанию: `'stringJsonAuto'`
130136

131137

132138
### Примеры

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dd/evolutioncms-snippets-ddobjecttools",
33
"type": "modxevo-snippet",
4-
"version": "0.6.0",
4+
"version": "0.7.0",
55
"description": "Tools for modifying objects.",
66
"keywords": [
77
"modx",
@@ -44,6 +44,6 @@
4444
],
4545
"require": {
4646
"php": ">=5.6.0",
47-
"dd/evolutioncms-libraries-ddtools": ">=0.51.0"
47+
"dd/evolutioncms-libraries-ddtools": ">=0.57.0"
4848
}
4949
}

ddObjectTools_snippet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* ddObjectTools
4-
* @version 0.6 (2023-03-08)
4+
* @version 0.7 (2023-03-30)
55
*
66
* @see README.md
77
*

src/Snippet.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,56 @@
33

44
class Snippet extends \DDTools\Snippet {
55
protected
6-
$version = '0.6.0',
6+
$version = '0.7.0',
77

88
$params = [
99
//Defaults
1010
'sourceObject' => '{}',
1111
'extend' => null,
1212
'getPropValue' => null,
13-
'outputter' => 'jsonAuto'
13+
'outputter' => 'stringJsonAuto'
1414
],
1515

1616
$paramsTypes = [
1717
'sourceObject' => 'objectAuto'
1818
]
1919
;
2020

21+
/**
22+
* prepareParams
23+
* @version 1.0 (2023-03-29)
24+
*
25+
* @param $params {stdClass|arrayAssociative|stringJsonObject|stringHjsonObject|stringQueryFormatted}
26+
*
27+
* @return {void}
28+
*/
29+
protected function prepareParams($params = []){
30+
parent::prepareParams($params);
31+
32+
//Backward compatibility
33+
$outputterFirstChars = substr(
34+
strtolower($this->params->outputter),
35+
0,
36+
4
37+
);
38+
if (
39+
$outputterFirstChars == 'json' ||
40+
$outputterFirstChars == 'quer'
41+
){
42+
$this->params->outputter =
43+
'string' .
44+
$this->params->outputter
45+
;
46+
}
47+
}
48+
2149
/**
2250
* run
23-
* @version 1.1 (2023-03-08)
51+
* @version 1.1.1 (2023-03-29)
2452
*
2553
* @return {string}
2654
*/
2755
public function run(){
28-
//The snippet must return an empty string even if result is absent
29-
$result = '';
30-
3156
//If need to extend
3257
if (!is_null($this->params->extend)){
3358
$this->params->extend = \DDTools\ObjectTools::convertType([
@@ -69,9 +94,7 @@ public function run(){
6994
){
7095
$result = \DDTools\ObjectTools::convertType([
7196
'object' => $result,
72-
'type' =>
73-
'string' .
74-
$this->params->outputter
97+
'type' => $this->params->outputter
7598
]);
7699
}
77100

0 commit comments

Comments
 (0)