Skip to content

Commit

Permalink
Version 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Jun 3, 2020
2 parents 27212f3 + dc2b54c commit 4c6f645
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 48 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


## 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`.
* \* Refactoring.
* \* README:
* \- Home page.
* \+ Links.
* \+ CHANGELOG_ru.


## Version 0.2 (2020-05-14)
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.34 is required.
* \+ Parameters → `sourceObject`.
Expand Down
41 changes: 41 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# (MODX)EvolutionCMS.snippets.ddObjectTools changelog


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


## Версия 0.2 (2020-05-14)
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.34.
* \+ Параметры → `sourceObject`.
* \+ Параметры → `getPropValue`. Возможность вернуть заданное свойство объекта / элемент массива.
* \+ Параметры → `extend`:
* \+ Объекты могут расширять массивы и наоборот.
* \+ Типы вложенных объектов независимы от типов их родителей.
* \+ Параметры → `extend->overwriteWithEmpty`. Возможность предотвратить перезапись полей пустыми значениями.
* \+ Параметры → `sourceObject`, `extend`: Могут быть заданы в виде объектов и массивов PHP, не только JSON строк (например, для вызовов через `$modx->runSnippet`).
* \* Если параметры не заданы или не валидны, будет возвращён пустой объект `'{}'`.
* \* Composer.json:
* \+ `homepage`.
* \+ `authors`.
* \+ `keywords`:
* \+ `extend json`.
* \+ `extend objects`.
* \+ `extend arrays`.
* \* `require` → `dd/evolutioncms-libraries-ddtools`:
* \* Переменовано из `dd/modxevo-library-ddtools`.
* \* Обновлён формат версии.


## Версия 0.1 (2020-04-23)
* \+ Первый релиз.


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
<style>ul{list-style:none;}</style>
21 changes: 14 additions & 7 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.4
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.34
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.38.1


## Documentation
Expand All @@ -17,7 +17,7 @@ Tools for modifying objects.

Elements → Snippets: Create a new snippet with the following data:
1. Snippet name: `ddObjectTools`.
2. Description: `<b>0.2</b> Tools for modifying objects.`.
2. Description: `<b>0.3</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 All @@ -30,16 +30,20 @@ Elements → Snippets: Create a new snippet with the following data:
* Valid values:
* `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
* `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
* `object`
* `array`
* `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`
* `array`
* Default: `'{}'`

* `extend`
* Desctription: Merge the contents of two or more objects together into `sourceObject` (it will receive the new properties).
* Valid values:
* `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
* `object`
* `arrayAssociative`
* `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`
* `arrayAssociative`
* Default value: —

* `extend->objects`
Expand Down Expand Up @@ -149,7 +153,10 @@ Returns `Chunk`.
Returns `Queen`.


## [Home page →](https://code.divandesign.biz/modx/ddobjecttools)
## Links

* [Home page](https://code.divandesign.biz/modx/ddobjecttools)
* [Telegram chat](https://t.me/dd_code)


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
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.2.0",
"version": "0.3.0",
"description": "Tools for modifying objects.",
"keywords": [
"modx",
Expand Down Expand Up @@ -41,6 +41,6 @@
],
"require": {
"php": ">=5.4.0",
"dd/evolutioncms-libraries-ddtools": ">=0.34.0"
"dd/evolutioncms-libraries-ddtools": ">=0.38.1"
}
}
61 changes: 22 additions & 39 deletions ddObjectTools_snippet.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* ddObjectTools
* @version 0.2 (2020-05-14)
* @version 0.3 (2020-06-03)
*
* @see README.md
*
* @link http://code.divandesign.biz/modx/ddobjecttools
* @link https://code.divandesign.biz/modx/ddobjecttools
*
* @copyright 2020 DD Group {@link https://www.DivanDesign.biz }
* @copyright 2020 DD Group {@link https://DivanDesign.biz }
*/

//Include (MODX)EvolutionCMS.libraries.ddTools
Expand All @@ -21,42 +21,26 @@

if (!isset($sourceObject)){
$sourceObject = '';
}

//If set as JSON
if (is_string($sourceObject)){
$sourceObject = json_decode($sourceObject);
}

if (
!is_object($sourceObject) &&
!is_array($sourceObject)
){
$sourceObject = new stdClass();
}else{
$sourceObject = \DDTools\ObjectTools::convertType([
'object' => $sourceObject,
'type' => 'objectAuto'
]);
}

//If need to extend
if (isset($extend)){
if (is_string($extend)){
$extend = json_decode($extend);
}
$extend = \DDTools\ObjectTools::convertType([
'object' => $extend,
'type' => 'objectArray'
]);

if (
is_object($extend) ||
is_array($extend)
){
//Prepend source object
if (is_object($extend)){
array_unshift(
$extend->objects,
$sourceObject
);
}else{
array_unshift(
$extend['objects'],
$sourceObject
);
}
//If is valid
if (!empty($extend)){
array_unshift(
$extend['objects'],
$sourceObject
);

$sourceObject = \DDTools\ObjectTools::extend($extend);
}
Expand All @@ -76,11 +60,10 @@
is_object($snippetResult) ||
is_array($snippetResult)
){
$snippetResult = json_encode(
$snippetResult,
//JSON_UNESCAPED_UNICODE — Не кодировать многобайтные символы Unicode | JSON_UNESCAPED_SLASHES — Не экранировать /
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
$snippetResult = \DDTools\ObjectTools::convertType([
'object' => $snippetResult,
'type' => 'stringJsonAuto'
]);
}

return $snippetResult;
Expand Down

0 comments on commit 4c6f645

Please sign in to comment.