Skip to content

Commit

Permalink
Version 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Nov 8, 2021
2 parents decb9ba + 6532b62 commit 9060ff1
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


## Version 0.5 (2021-11-08)
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.51 is required.
* \+ Parameters → `outputter`: The new parameter. Allows to forcibly convert the snippet result into a JSON object/array or URL-encoded query string if needed.


## Version 0.4 (2021-04-28)
* \* Attention! PHP >= 5.6 is required.
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.49.1 is required.
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


## Версия 0.5 (2021-11-08)
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.51.
* \+ Параметры → `outputter`: Новый параметр. Позволяет принудительно преобразовать результат сниппета в JSON объект/массив или URL-кодированную строку запроса, если это необходимо.


## Версия 0.4 (2021-04-28)
* \* Внимание! Требуется PHP >= 5.6.
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.49.1.
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tools for modifying objects.

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


## Documentation
Expand All @@ -22,7 +22,7 @@ Tools for modifying objects.
##### 1. Elements → Snippets: Create a new snippet with the following data

1. Snippet name: `ddObjectTools`.
2. Description: `<b>0.4</b> Tools for modifying objects.`.
2. Description: `<b>0.5</b> Tools for modifying objects.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddObjectTools_snippet.php` file from the archive.
Expand Down Expand Up @@ -113,6 +113,16 @@ require_once(
* Desctription: Object property name or array index / key to return.
* Valid values: `string`
* Default value: —

* `outputter`
* Desctription: Output format (when result is an object or array).
Values are case insensitive (the following values are equal: `'jsonauto'`, `'JsonAuto'`, `'JSONAUTO'`, etc).
* Valid values:
* `'jsonAuto'` — `jsonObject` or `jsonArray` depends on result object
* `'jsonObject'`
* `'jsonArray'`
* `'queryFormated'` — [Query string](https://en.wikipedia.org/wiki/Query_string)
* Default value: `'jsonAuto'`


### Examples
Expand Down Expand Up @@ -189,6 +199,28 @@ Returns: `Chuck`.
Returns: `Queen`.


#### Convert a JSON object to an array

```
[[ddObjectTools?
&sourceObject=`{
"firstName": "Angus",
"lastName": "Young"
}`
&outputter=`jsonArray`
]]
```

Returns:

```json
[
"Angus",
"Young"
]
```


#### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

```php
Expand Down
36 changes: 34 additions & 2 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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


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

1. Название сниппета: `ddObjectTools`.
2. Описание: `<b>0.4</b> Tools for modifying objects.`.
2. Описание: `<b>0.5</b> Tools for modifying objects.`.
3. Категория: `Core`.
4. Анализировать DocBlock: `no`.
5. Код сниппета (php): Вставьте содержимое файла `ddObjectTools_snippet.php` из архива.
Expand Down Expand Up @@ -113,6 +113,16 @@ require_once(
* Описание: Возврат значения поля объекта или элемента массива по имени свойства объекта или индексу / ключу массива.
* Допустимые значения: `string`
* Значение по умолчанию: —

* `outputter`
* Описание: Формат вывода (когда результат является объектом или массивом).
Значения регистронезависимы (следующие значения равны: `jsonauto`, `JsonAuto`, `JSONAUTO` и т. п.).
* Допустимые значения:
* `'jsonAuto'` — автоматиески будет выбран `jsonObject` или `jsonArray`, в зависимости от результата
* `'jsonObject'`
* `'jsonArray'`
* `'queryFormated'` — [Query string](https://ru.wikipedia.org/wiki/Query_string)
* Значение по умолчанию: `'jsonAuto'`


### Примеры
Expand Down Expand Up @@ -189,6 +199,28 @@ require_once(
Вернёт: `Queen`.


#### Сконвертировать JSON объект в массив

```
[[ddObjectTools?
&sourceObject=`{
"firstName": "Angus",
"lastName": "Young"
}`
&outputter=`jsonArray`
]]
```

Вернёт:

```json
[
"Angus",
"Young"
]
```


#### Запустить сниппет через `\DDTools\Snippet::runSnippet` без DB и eval

```php
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dd/evolutioncms-snippets-ddobjecttools",
"type": "modxevo-snippet",
"version": "0.4.0",
"version": "0.5.0",
"description": "Tools for modifying objects.",
"keywords": [
"modx",
Expand Down Expand Up @@ -44,6 +44,6 @@
],
"require": {
"php": ">=5.6.0",
"dd/evolutioncms-libraries-ddtools": ">=0.49.1"
"dd/evolutioncms-libraries-ddtools": ">=0.51.0"
}
}
2 changes: 1 addition & 1 deletion ddObjectTools_snippet.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ddObjectTools
* @version 0.4 (2021-04-28)
* @version 0.5 (2021-11-08)
*
* @see README.md
*
Expand Down
9 changes: 6 additions & 3 deletions src/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

class Snippet extends \DDTools\Snippet {
protected
$version = '0.4.0',
$version = '0.5.0',

$params = [
//Defaults
'sourceObject' => '{}',
'extend' => null,
'getPropValue' => null
'getPropValue' => null,
'outputter' => 'jsonAuto'
],

$paramsTypes = [
Expand Down Expand Up @@ -61,7 +62,9 @@ public function run(){
){
$result = \DDTools\ObjectTools::convertType([
'object' => $result,
'type' => 'stringJsonAuto'
'type' =>
'string' .
$this->params->outputter
]);
}

Expand Down

0 comments on commit 9060ff1

Please sign in to comment.