@@ -5,45 +5,81 @@ Tools for modifying objects.
55
66## Requires
77
8- * PHP >= 5.4
8+ * 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.38 .1
10+ * [ (MODX)EvolutionCMS.libraries.ddTools] ( https://code.divandesign.biz/modx/ddtools ) >= 0.49 .1
1111
1212
1313## Documentation
1414
1515
1616### Installation
1717
18- Elements → Snippets: Create a new snippet with the following data:
18+
19+ #### Manually
20+
21+
22+ ##### 1. Elements → Snippets: Create a new snippet with the following data
23+
19241 . Snippet name: ` ddObjectTools ` .
20- 2 . Description: ` <b>0.3 </b> Tools for modifying objects. ` .
25+ 2 . Description: ` <b>0.4 </b> Tools for modifying objects. ` .
21263 . Category: ` Core ` .
22274 . Parse DocBlock: ` no ` .
23285 . Snippet code (php): Insert content of the ` ddObjectTools_snippet.php ` file from the archive.
2429
2530
31+ ##### 2. Elements → Manage Files
32+
33+ 1 . Create a new folder ` assets/snippets/ddObjectTools/ ` .
34+ 2 . Extract the archive to the folder (except ` ddObjectTools_snippet.php ` ).
35+
36+
37+ #### Using [ (MODX)EvolutionCMS.libraries.ddInstaller] ( https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller )
38+
39+ Just run the following PHP code in your sources or [ Console] ( https://github.com/vanchelo/MODX-Evolution-Ajax-Console ) :
40+
41+ ``` php
42+ //Include (MODX)EvolutionCMS.libraries.ddInstaller
43+ require_once(
44+ $modx->getConfig('base_path') .
45+ 'assets/libs/ddInstaller/require.php'
46+ );
47+
48+ //Install (MODX)EvolutionCMS.snippets.ddObjectTools
49+ \DDInstaller::install([
50+ 'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddObjectTools',
51+ 'type' => 'snippet'
52+ ]);
53+ ```
54+
55+ * If ` ddObjectTools ` is not exist on your site, ` ddInstaller ` will just install it.
56+ * If ` ddObjectTools ` is already exist on your site, ` ddInstaller ` will check it version and update it if needed.
57+
58+
2659### Parameters description
2760
2861* ` sourceObject `
2962 * Desctription: Source object or array.
3063 * Valid values:
3164 * `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
3265 * `stringJsonArray` — as [JSON](https://en.wikipedia.org/wiki/JSON)
66+ * `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
67+ * `stringHjsonArray` — as [HJSON](https://hjson.github.io/)
3368 * `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
34- * It can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`).
35- * `object`
69+ * It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
3670 * `array`
37- * Default: `'{}'`
71+ * `object`
72+ * Default value: `'{}'`
3873
3974* ` extend `
40- * Desctription: Merge the contents of two or more objects together into `sourceObject` (it will receive the new properties).
75+ * Desctription: Merge the contents of two or more objects / arrays together into `sourceObject` (it will receive the new properties).
4176 * Valid values:
4277 * `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
78+ * `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
4379 * `stringQueryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
44- * It can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`).
45- * `object`
80+ * It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
4681 * `arrayAssociative`
82+ * `object`
4783 * Default value: —
4884
4985* ` extend->objects `
@@ -59,7 +95,7 @@ Elements → Snippets: Create a new snippet with the following data:
5995 * **Required**
6096
6197* ` extend->deep `
62- * Desctription: If true, the merge becomes recursive (aka. deep copy).
98+ * Desctription: If true, the merge becomes recursive (aka “ deep copy” ).
6399 * Valid values: `boolean`
64100 * Default value: `true`
65101
@@ -74,7 +110,7 @@ Elements → Snippets: Create a new snippet with the following data:
74110 * Default value: `true`
75111
76112* ` getPropValue `
77- * Desctription: Object property name or array index to return.
113+ * Desctription: Object property name or array index / key to return.
78114 * Valid values: `string`
79115 * Default value: —
80116
@@ -117,7 +153,7 @@ Returns:
117153 "weight" : 10 ,
118154 },
119155 "rabbit" : 42 ,
120- "bird" : 0 ,
156+ "bird" : 0
121157}
122158```
123159
@@ -127,14 +163,14 @@ Returns:
127163```
128164[[ddObjectTools?
129165 &sourceObject=`{
130- "firstName": "Chunk ",
166+ "firstName": "Chuck ",
131167 "lastName": "Norris"
132168 }`
133169 &getPropValue=`firstName`
134170]]
135171```
136172
137- Returns ` Chunk ` .
173+ Returns: ` Chuck ` .
138174
139175
140176#### Get an array element
@@ -150,13 +186,50 @@ Returns `Chunk`.
150186]]
151187```
152188
153- Returns ` Queen ` .
189+ Returns: ` Queen ` .
190+
191+
192+ #### Run the snippet through ` \DDTools\Snippet::runSnippet ` without DB and eval
193+
194+ ``` php
195+ //Include (MODX)EvolutionCMS.libraries.ddTools
196+ require_once(
197+ $modx->getConfig('base_path') .
198+ 'assets/libs/ddTools/modx.ddtools.class.php'
199+ );
200+
201+ //Run (MODX)EvolutionCMS.snippets.ddObjectTools
202+ \DDTools\Snippet::runSnippet([
203+ 'name' => 'ddObjectTools',
204+ 'params' => [
205+ 'sourceObject' => [
206+ 'cat' => 'mew',
207+ 'dog' => [
208+ 'name' => 'Floyd',
209+ 'weight' => 6
210+ ],
211+ 'rabbit' => 42
212+ ],
213+ 'extend' => [
214+ 'objects' => [
215+ [
216+ 'dog' => [
217+ 'weight' => 11
218+ ],
219+ 'bird' => 0
220+ ]
221+ ]
222+ ]
223+ ]
224+ ]);
225+ ```
154226
155227
156228## Links
157229
158230* [ Home page] ( https://code.divandesign.biz/modx/ddobjecttools )
159231* [ Telegram chat] ( https://t.me/dd_code )
232+ * [ Packagist] ( https://packagist.org/packages/dd/evolutioncms-snippets-ddobjecttools )
160233
161234
162235<link rel =" stylesheet " type =" text/css " href =" https://DivanDesign.ru/assets/files/ddMarkdown.css " />
0 commit comments