Tools for modifying objects.
- PHP >= 5.4
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.34
Elements → Snippets: Create a new snippet with the following data:
- Snippet name:
ddObjectTools. - Description:
<b>0.2</b> Tools for modifying objects.. - Category:
Core. - Parse DocBlock:
no. - Snippet code (php): Insert content of the
ddObjectTools_snippet.phpfile from the archive.
-
sourceObject -
extend- Desctription: Merge the contents of two or more objects together into
sourceObject(it will receive the new properties). - Valid values:
stringJsonObject— as JSONobjectarrayAssociative
- Default value: —
- Desctription: Merge the contents of two or more objects together into
-
extend->objects- Desctription: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
- Valid values:
array - Required
-
extend->objects[i]- Desctription: An object or array containing additional properties to merge in.
- Valid values:
objectarray
- Required
-
extend->deep- Desctription: If true, the merge becomes recursive (aka. deep copy).
- Valid values:
boolean - Default value:
true
-
extend->overwriteWithEmpty- Desctription: Overwrite fields with empty values.
The following values are considered to be empty:''— an empty string[]— an empty array(object) []— an empty objectNULL
- Valid values:
boolean - Default value:
true
- Desctription: Overwrite fields with empty values.
-
getPropValue- Desctription: Object property name or array index to return.
- Valid values:
string - Default value: —
[[ddObjectTools?
&sourceObject=`{
"cat": "mew",
"dog": {
"name": "Floyd",
"weight": 6
},
"rabbit": 42
}`
&extend=`{
"objects": [
{
"dog": {
"weight": 10
},
"bird": 0
}
]
}`
]]
Returns:
{
"cat": "mew",
"dog": {
"name": "Floyd",
"weight": 10,
},
"rabbit": 42,
"bird": 0,
}[[ddObjectTools?
&sourceObject=`{
"firstName": "Chunk",
"lastName": "Norris"
}`
&getPropValue=`firstName`
]]
Returns Chunk.
[[ddObjectTools?
&sourceObject=`[
"Pink Floyd",
"The Beatles",
"Queen"
]`
&getPropValue=`2`
]]
Returns Queen.