Skip to content

Commit

Permalink
Version 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Apr 28, 2021
2 parents 4c6f645 + fcf346f commit decb9ba
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 73 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


## Version 0.4 (2021-04-28)
* \* Attention! PHP >= 5.6 is required.
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.49.1 is required.
* \+ Parameters → `sourceObject`, `extend`: Can also be set as [HJSON](https://hjson.github.io/).
* \+ You can just call `\DDTools\Snippet::runSnippet` to run the snippet without DB and eval (see README → Examples).
* \+ `\ddObjectTools\Snippet`: The new class. All snippet code was moved here.
* \+ README:
* \+ Documentation → Installation → Using (MODX)EvolutionCMS.libraries.ddInstaller.
* \+ Links → Packagist.
* \+ Text improvements.
* \+ README_ru.
* \+ Composer.json → `support`.


## Version 0.3 (2020-06-03)
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.38.1 is required.
* \+ Parameters → `sourceObject`, `extend`: Can also be set as `stringQueryFormated`.
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


## Version 0.3 (2020-06-03)
## Версия 0.4 (2021-04-28)
* \* Внимание! Требуется PHP >= 5.6.
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.49.1.
* \+ Параметры → `sourceObject`, `extend`: Также может быть задан, как [HJSON](https://hjson.github.io/).
* \+ Запустить сниппет без DB и eval можно через `\DDTools\Snippet::runSnippet` (см. примеры в README).
* \+ `\ddObjectTools\Snippet`: Новый класс. Весь код сниппета перенесён туда.
* \+ README:
* \+ Документация → Установка → Используя (MODX)EvolutionCMS.libraries.ddInstaller.
* \+ Ссылки → Packagist.
* \+ Улучшения текста.
* \+ README_ru.
* \+ Composer.json → `support`.


## Версия 0.3 (2020-06-03)
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.38.1.
* \+ Параметры → `sourceObject`, `extend`: Также может задаваться как `stringQueryFormated`.
* \* Рефакторинг.
Expand Down
105 changes: 89 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,81 @@ Tools for modifying objects.

## Requires

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


## Documentation


### Installation

Elements → Snippets: Create a new snippet with the following data:

#### Manually


##### 1. Elements → Snippets: Create a new snippet with the following data

1. Snippet name: `ddObjectTools`.
2. Description: `<b>0.3</b> Tools for modifying objects.`.
2. Description: `<b>0.4</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.


##### 2. Elements → Manage Files

1. Create a new folder `assets/snippets/ddObjectTools/`.
2. Extract the archive to the folder (except `ddObjectTools_snippet.php`).


#### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller)

Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console):

```php
//Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
$modx->getConfig('base_path') .
'assets/libs/ddInstaller/require.php'
);

//Install (MODX)EvolutionCMS.snippets.ddObjectTools
\DDInstaller::install([
'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddObjectTools',
'type' => 'snippet'
]);
```

* If `ddObjectTools` is not exist on your site, `ddInstaller` will just install it.
* If `ddObjectTools` is already exist on your site, `ddInstaller` will check it version and update it if needed.


### Parameters description

* `sourceObject`
* Desctription: Source object or array.
* Valid values:
* `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
* `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
* `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
* `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
* `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
* It can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`).
* `object`
* It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
* `array`
* Default: `'{}'`
* `object`
* Default value: `'{}'`

* `extend`
* Desctription: Merge the contents of two or more objects together into `sourceObject` (it will receive the new properties).
* Desctription: Merge the contents of two or more objects / arrays together into `sourceObject` (it will receive the new properties).
* Valid values:
* `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)
* It can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`).
* `object`
* It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
* `arrayAssociative`
* `object`
* Default value: —

* `extend->objects`
Expand All @@ -59,7 +95,7 @@ Elements → Snippets: Create a new snippet with the following data:
* **Required**

* `extend->deep`
* Desctription: If true, the merge becomes recursive (aka. deep copy).
* Desctription: If true, the merge becomes recursive (akadeep copy).
* Valid values: `boolean`
* Default value: `true`

Expand All @@ -74,7 +110,7 @@ Elements → Snippets: Create a new snippet with the following data:
* Default value: `true`

* `getPropValue`
* Desctription: Object property name or array index to return.
* Desctription: Object property name or array index / key to return.
* Valid values: `string`
* Default value: —

Expand Down Expand Up @@ -117,7 +153,7 @@ Returns:
"weight": 10,
},
"rabbit": 42,
"bird": 0,
"bird": 0
}
```

Expand All @@ -127,14 +163,14 @@ Returns:
```
[[ddObjectTools?
&sourceObject=`{
"firstName": "Chunk",
"firstName": "Chuck",
"lastName": "Norris"
}`
&getPropValue=`firstName`
]]
```

Returns `Chunk`.
Returns: `Chuck`.


#### Get an array element
Expand All @@ -150,13 +186,50 @@ Returns `Chunk`.
]]
```

Returns `Queen`.
Returns: `Queen`.


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

```php
//Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
$modx->getConfig('base_path') .
'assets/libs/ddTools/modx.ddtools.class.php'
);

//Run (MODX)EvolutionCMS.snippets.ddObjectTools
\DDTools\Snippet::runSnippet([
'name' => 'ddObjectTools',
'params' => [
'sourceObject' => [
'cat' => 'mew',
'dog' => [
'name' => 'Floyd',
'weight' => 6
],
'rabbit' => 42
],
'extend' => [
'objects' => [
[
'dog' => [
'weight' => 11
],
'bird' => 0
]
]
]
]
]);
```


## Links

* [Home page](https://code.divandesign.biz/modx/ddobjecttools)
* [Telegram chat](https://t.me/dd_code)
* [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddobjecttools)


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
Loading

0 comments on commit decb9ba

Please sign in to comment.