Just add dd/evolutioncms-libraries-ddtools to your composer.json., (*2)
ddTools version must be 0.14 or higher to use this method. If you use it, the compatibility with all your snippets, modules, etc. that use ddTools versions under 0.14 will be maintained., (*3)
If ddTools is already exist on your site, ddInstaller will check it version and update it if needed.
If ddTools is not exist on your site, ddInstaller can't do anything because requires it for itself.
Parameters description
\ddTools::convertUrlToAbsolute($params)
Converts relative URLs to absolute., (*5)
The method tends to change URL as little as possible and just prepends required scheme and/or host (or sometimes nothing at all).
All kinds of query parameters, hash, ports, etc. are not modified., (*6)
$params, (*7)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->url, (*8)
Desctription: Source URL. Can be set as:
'some/url' — relative
'/some/url' — relative starting with slash
'example.com/some/url' — absolute starting with domain
'//example.com/some/url' — absolute starting with double slash
'https://example.com/some/url' — absolute starting with scheme
Valid values: string
Required
$params->host, (*9)
Desctription: Host for the result URL.
Valid values: string
Default value: $_SERVER['HTTP_HOST']
$params->scheme, (*10)
Desctription: Scheme for the result URL.
Valid values: string
Default value: 'https' or 'http' depending on $_SERVER['HTTPS']
Returns
$result
Desctription: Source URL converted to absolute. Always contains scheme.
Valid values: string
\ddTools::getTpl($tpl = '')
The same as $modx->getTpl with some differences:
* This method always returns string regardless of the parameter type. For example, $modx->getTpl(null) returns null, this method returns ''.
* The parameter is optional. $modx->getTpl() throws an error, this method jsut returns ''.
* $modx->getTpl('@CODE:') returns '@CODE:', this method returns ''., (*11)
$tpl
Desctription: Chunk name or inline template.
Valid values:
stringChunkName
string — use inline templates starting with @CODE:
Default value: ''
Returns
$result
Desctription: Required template.
Valid values: string
\ddTools::parseText($params)
Replaces placeholders in a text with required values.
Like $modx->parseChunk, but takes a text and has some features., (*12)
$params, (*13)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->text, (*14)
Desctription: String to parse.
Valid values: string
Required
$params->data, (*15)
Desctription:
The array of additional data has to be replaced in $params->text.
Nested objects and arrays are supported too:
Valid values: Key is placeholder name, value is value.
string
array
object
Required
$params->placeholderPrefix, (*17)
Desctription: Placeholders prefix.
Valid values: string
Default value: '[+'
$params->placeholderSuffix, (*18)
Desctription: Placeholders suffix.
Valid values: string
Default value: '+]'
$params->removeEmptyPlaceholders, (*19)
Desctription: Do you need to remove empty placeholders?
Valid values: boolean
Default value: false
$params->mergeAll, (*20)
Desctription: Additional parsing of document fields, settings, chunks.
Valid values: boolean
Default value: true
Returns
$result
Desctription: Parsed text.
Valid values: string
\ddTools::verifyRenamedParams($params)
The method checks an array for deprecated parameters and writes warning messages into the MODX event log.
It returns an associative array, in which the correct parameter names are the keys and the parameter values are the values.
You can use the exctract function to turn the array into variables of the current symbol table., (*21)
$params, (*22)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->params, (*23)
Desctription: The associative array of the parameters of a snippet, in which the parameter names are the keys and the parameter values are the values.
You can directly pass here the $params variable if you call the method inside of a snippet.
Valid values:
stdClass
arrayAssociative
Required
$params->compliance, (*24)
Desctription: An array (or object) of correspondence between new parameter names and old ones, in which the new names are the keys and the old names are the values.
Valid values:
stdClass
arrayAssociative
Required
$params->compliance->{$newName}, (*25)
Desctription: The old name(s). Use a string for a single name or an array for multiple.
Valid values:
string
array
Required
$params->compliance->{$newName}[i], (*26)
Desctription: One of the old names.
Valid values: string
Required
$params->returnCorrectedOnly, (*27)
Desctription: Need to return only corrected parameters?
Valid values: boolean
Default value: true
$params->writeToLog, (*28)
Desctription: Write a warning message about deprecated parameters to the CMS event log.
Valid values: boolean
Default value: true
Returns
$result, (*29)
Desctription: An array or object, in which the correct parameter names are the keys and the parameter values are the values.
Can contains all parameters or only corrected (see $params->returnCorrectedOnly).
Valid values:
arrayAssociative — if $params->params set as an array
stdClass — if $params->params set as an object
$result[$newName], (*30)
Desctription: A parameter value, in which the correct parameter name is the key and the parameter value is the value.
Valid values: mixed
\DDTools\FilesTools
\DDTools\FilesTools::modifyImage($params)
Modify your images: create thumbnails, crop, resize, fill background color or add watermark., (*31)
$params, (*32)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->sourceFullPathName, (*33)
Desctription: Full file path of source image.
You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
Valid values: string
Required
$params->outputFullPathName, (*34)
Desctription: Full file path of result image.
You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
The original image will be overwritten if this parameter is omitted.
Valid values: string
Default value: == $params->sourceFullPathName
$params->transformMode, (*35)
Desctription: Transform mode.
Valid values:
'resize' — resize only, the image will be inscribed into the specified sizes with the same proportions
'crop' — crop only
'resizeAndCrop' — resize small side then crop big side to the specified value
'resizeAndFill' — inscribe image into the specified sizes and fill empty space with the specified background (see $params->backgroundColor)
Default value: 'resize'
$params->width, (*36)
Desctription: Result image width.
In pair width / height only one is required, omitted size will be calculated according to the image proportions.
Valid values: integer
Required
$params->height, (*37)
Desctription: Result image height.
In pair width / height only one is required, omitted size will be calculated according to the image proportions.
Valid values: integer
Required
$params->allowEnlargement, (*38)
Desctription: Allow image enlargement when resizing.
Valid values: boolean
Default value: false
$params->backgroundColor, (*39)
Desctription: Result image background color in HEX (used only for $params->transformMode == 'resizeAndFill').
Valid values: string
Default value: FFFFFF
$params->allowEnlargement, (*40)
Desctription: Allow image enlargement when resizing.
Valid values: boolean
Default value: false
$params->quality, (*41)
Desctription: JPEG compression level.
Valid values: integer
Default value: 100
$params->watermarkImageFullPathName, (*42)
Desctription: Specify if you want to overlay your image with watermark.
You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
Valid values: string
Default value: —
\DDTools\ObjectTools
\DDTools\ObjectTools::isPropExists($params)
Checks if the object, class or array has a property / element.
This is a “syntactic sugar” for checking an element in one way regardless of the “object” type., (*43)
The first reason for creating this method is convenience to not thinking about type of “object” variables.
Second, the different order of parameters in the native PHP functions makes us crazy., (*44)
$params, (*45)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->object, (*46)
Desctription: Source object or array.
Valid values:
stdClass
array
Required
$params->propName, (*47)
Desctription: Object property name or array key.
Valid values:
string
integer
Required
\DDTools\ObjectTools::getPropValue($params)
Get the value of an object property or an array element in any nesting level in one way regardless of the “object” type., (*48)
$params, (*49)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->object, (*50)
Desctription: Source object or array.
It can be nested, and elements of all levels can be mix of objects and arrays (see Examples below).
Valid values:
stdClass
array
Required
$params->propName, (*51)
Desctription: Object property name or array key.
You can also use '.' to get nested properties. Several examples (see also full Examples below):
somePlainProp — get first-level property
someObjectProp.secondLevelProp — get property of the someObjectProp object|array
someArrayProp.0.thirdLevelProp — get property of the zero element of the someArrayProp array
Valid values:
string
integer
Required
Returns
$result
Desctription: Value of an object property or an array element.
Valid values:
mixed
NULL — if property not exists
\DDTools\ObjectTools::convertType($params)
Converts an object type.
Arrays, JSON and Query string objects are also supported., (*52)
$params, (*53)
Desctription: Parameters, the pass-by-name style is used.
Desctription: Type of resulting object.
Values are case insensitive (the following names are equal: 'stringjsonauto', 'stringJsonAuto', 'STRINGJSONAUTO', etc).
Valid values:
'objectAuto' — stdClass or array depends on input object
'objectStdClass' — stdClass
'objectArray' — array
'stringJsonAuto' — stringJsonObject or stringJsonArray depends on input object
'stringJsonObject'
'stringJsonArray'
'stringQueryFormatted'
'stringHtmlAttrs' — HTML attributes string (e. g. width='100' height='50'), boolean values will be converted to 0 or 1 (e. g. data-is-loaded='1'), objects/arrays will be converted to JSON string (e. g. data-user-data='{"firstName": "Elon", "lastName": "Musk"}')
Default value: 'objectAuto'
Returns
$result
Desctription: Result type depends on $params->type.
Valid values:
stdClass
array
stringJsonObject
stringJsonArray
\DDTools\ObjectTools::extend($params)
Merge the contents of two or more objects or arrays together into the first one., (*56)
$params, (*57)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->objects, (*58)
Desctription: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
Valid values: array
Required
$params->objects[0], (*59)
Desctription: The object or array to extend. It will receive the new properties.
Valid values:
object
array
mixed — if passed something else, the new stdClass object will be created instead
Required
$params->objects[i], (*60)
Desctription: An object or array containing additional properties to merge in.
Valid values:
object
array
Required
$params->deep, (*61)
Desctription: If true, the merge becomes recursive (aka. deep copy).
Valid values: boolean
Default value: true
$params->overwriteWithEmpty, (*62)
Desctription: Overwrite fields with empty values (see examples below).
The following values are considered to be empty:
'' — an empty string
[] — an empty array
(object) [] — an empty object
NULL
Valid values: boolean
Default value: true
\DDTools\ObjectTools::unfold($params)
Converts a multidimensional array/object into an one-dimensional one joining the keys with $params->keySeparator.
For example, it can be helpful while using placeholders like [+size.width+]., (*63)
$params, (*64)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->object, (*65)
Desctription: An object/array to convert.
Valid values:
stdClass
arrayAssociative
Required
$params->keySeparator, (*66)
Desctription: Separator between nested keys in the result object/array.
Valid values: string
Default value: '.'
$params->keyPrefix, (*67)
Desctription: Prefix of the keys of an object/array (it's an internal varible, but can be used if required).
Valid values: string
Default value: ''
Returns
$result
Desctription: Unfolded object/array. Type of results depends on $params->object.
Valid values:
stdClass
array
\DDTools\ObjectCollection
Class representing a collection of some objects or arrays., (*68)
\DDTools\ObjectCollection::__construct($params)
$params, (*69)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Default value: —
$params->items, (*70)
Desctription: An array of items.
You can avoid this parameter to create an empty collection and set items later.
Valid values:
array — can be indexed or associative, keys will not be used
object — also can be set as an object for better convenience, only property values will be used
array — indexed arrays are supported as well as associative
object
Required
$params->itemType, (*72)
Desctription: Allows to convert item type. If set, each item of $params->items will be converted to needed type.
Values are case insensitive (the following names are equal: 'objectstdclass', 'objectStdClass', 'OBJECTSTDCLASS', etc).
Valid values:
'objectStdClass'
'objectArray'
null — do not convert type of items, use them as is
Default value: null
\DDTools\ObjectCollection::setItems($params)
Sets new collection items. Existing items will be removed., (*73)
Has the same parameters as \DDTools\ObjectCollection::__construct($params)., (*74)
\DDTools\ObjectCollection::addItems($params)
Appends items onto the end of collection., (*75)
Has the same parameters as \DDTools\ObjectCollection::__construct($params)., (*76)
\DDTools\ObjectCollection::getItems($params)
Gets an array of required collection items., (*77)
$params, (*78)
Desctription: Parameters, the pass-by-name style is used.
All items with the gender property equal to 'female'.
All items:
with the gender property equal to 'male'and
with the firstName property not equal to 'Bill'and
with the lastName property is exist with any value.
Quoted property names and values are optional, this is valid too:
'
gender == female ||
gender == male &&
firstName != Bill &&
lastName
'
Single quotes are also supported as double quotes:
"
gender == 'a' ||
gender == 'b' &&
firstName != 'Bill' &&
lastName
"
Spaces, tabs and line breaks are optional, this is valid too: gender==female||gender==male&&firstName!=Bill&&lastName.
Valid values: stringSeparated
Default value: '' (without filtration)
$params->limit, (*80)
Desctription: Maximum number of items to return.
Valid values:
integer
0 — all matching items
Default value: 0
$params->propAsResultKey, (*81)
Desctription: Item property, which value will be an item key in result array instead of an item index.
For example, it can be useful if items have an ID property or something like that.
Valid values:
string
null — result array will be indexed
Default value: null
$params->propAsResultValue, (*82)
Desctription: Item property, which value will be an item value in result array instead of an item object.
Valid values:
string
null — result array values will item objects
Default value: null
Returns
$result, (*83)
Desctription: An array of items.
Valid values:
arrayIndexed
arrayAssociative — item property values will be used as result keys if $params->propAsResultKey is set
$result[$itemIndex|$itemFieldValue], (*84)
Desctription: An item object or item property value if specified in $params->propAsResultValue.
Valid values: mixed
\DDTools\ObjectCollection::getOneItem($params)
Gets required item., (*85)
$params, (*86)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Default value: —
$params->filter, (*87)
Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
Valid values: stringSeparated
Default value: '' (first found item will be returned)
$params->notFoundResult, (*88)
Desctription: What will be returned when no items found.
Converts type of needed items in collection., (*90)
$params, (*91)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Default value: —
$params->itemType, (*92)
Desctription: Result item type.
Values are case insensitive (the following names are equal: 'objectstdclass', 'objectStdClass', 'OBJECTSTDCLASS', etc).
Valid values:
'objectStdClass'
'objectArray'
Required
$params->filter, (*93)
Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
Valid values: stringSeparated
Default value: '' (all items will be converted)
\DDTools\ObjectCollection::updateItems($params)
Undates properties of existing items with new values., (*94)
$params, (*95)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->data, (*96)
Desctription: New item data. Existing item will be extended by this data, it means:
Type of existing item will not be changed.
All given property values will overwrite existing.
Non-existing given properties will be created.
Existing properties that absent in $params->data will remain as is.
Valid values:
array
object
Required
$params->filter, (*97)
Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
Valid values: stringSeparated
Default value: '' (any items will be updated)
$params->limit, (*98)
Desctription: Maximum number of items can be updated.
Valid values:
integer
0 — all matching items
Default value: 0
\DDTools\ObjectCollection::deleteItems($params)
Deletes required items from collection., (*99)
$params, (*100)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Default value: —
$params->filter, (*101)
Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
Valid values: stringSeparated
Default value: '' (any items will be deleted)
$params->limit, (*102)
Desctription: Maximum number of items can be deleted.
Sets data of an item object. All setting of an item data inside the class must be use this method.
It's convenient to override this method in child classes if items are not plain objects., (*104)
$params, (*105)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->itemIndex, (*106)
Desctription: Item index which data will be set.
Valid values: integer
Required
$params->itemData, (*107)
Desctription: New item data.
Valid values:
array — indexed arrays are supported as well as associative
Returns data of an item object. All getting of an item data inside the class must use this method.
It's convenient to override this method in child classes if items are not plain objects., (*108)
$params, (*109)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->itemObject, (*110)
Desctription: An item object which data will be returned.
Valid values:
array — indexed arrays are supported as well as associative
object
Required
Returns
$result
Desctription: Data of an item object.
Valid values:
array
object
\DDTools\Base\Base
Simple abstract class with some small methods facilitating your work.
It is convenient to inherit your classes from this., (*111)
Desctription: Parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
Required
$params->name, (*126)
Desctription: Class name.
Valid values: string
Required
$params->params, (*127)
Desctription: Params to be passed to object constructor.
Valid values:
stdClass
arrayAssociative
Default value: []
$params->parentDir, (*128)
Desctription: Directory of the parent file (e. g. __DIR__).
Valid values: string
Default value: — (dirname of a class that uses this trait)
$params->capitalizeName, (*129)
Desctription: Need to capitalize child name?
Valid values: boolean
Default value: true
Returns
$result
Desctription: The new object instance.
Valid values: object
\DDTools\Snippet
Abstract class for snippets., (*130)
Properties
\DDTools\Snippet::$name, (*131)
Desctription: Snippet name (e. g. ddGetDocuments).
Will be set from namespace in \DDTools\Snippet::__construct($params).
You can use it inside child classes: $this->name.
Valid values: string
Visibility: protected
\DDTools\Snippet::$version, (*132)
Desctription: Snippet version.
You must define it in your child class declaration.
Valid values: string
Visibility: protected
\DDTools\Snippet::$paths, (*133)
Desctription: Snippet paths.
Will be set in \DDTools\Snippet::__construct($params).
Valid values: stdClass
Visibility: protected
\DDTools\Snippet::$paths->snippet, (*134)
Desctription: Full path to the snippet folder.
Valid values: string
\DDTools\Snippet::$paths->src, (*135)
Desctription: Ful path to the src folder.
Valid values: string
\DDTools\Snippet::$params, (*136)
Desctription: Snippet params.
Will be set in \DDTools\Snippet::__construct($params).
You can define default values of parameters as associative array in this field of your child class (e. g. protected $params = ['someParameter' => 'valueByDefault'];);.
Valid values: stdClass
Visibility: protected
\DDTools\Snippet::$params->{$paramName}, (*137)
Desctription: Key is parameter name, value is value.
Valid values: mixed
\DDTools\Snippet::$paramsTypes, (*138)
Desctription: Overwrite in child classes if you want to convert some parameters types.
Parameters types will be converted respectively with this field in \DDTools\Snippet::prepareParams.
Desctription: The parameter type.
Values are case insensitive (the following names are equal: 'stringjsonauto', 'stringJsonAuto', 'STRINGJSONAUTO', etc).
Desctription: Overwrite in child classes if you want to rename some parameters with backward compatibility (see $params->compliance of \ddTools::verifyRenamedParams).
Valid values: arrayAssociative
Visibility: protected
\DDTools\Snippet::__construct($params)
$params, (*141)
Desctription: Snippet parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
stringJsonObject
stringQueryFormatted
Default value: []
$params->{$paramName}, (*142)
Desctription: Key is parameter name, value is value.
Valid values: mixed
Required
\DDTools\Snippet::run()
Abstract method for main snippet action., (*143)
You must define it in your child class declaration., (*144)
\DDTools\Snippet::runSnippet($params)
Static method for easy running needed snippet using only it's name and parameters (if needed)., (*145)
$params, (*146)
Desctription: Snippet parameters, the pass-by-name style is used.
Valid values:
stdClass
arrayAssociative
stringJsonObject
stringQueryFormatted
Required
$params->name, (*147)
Desctription: The name of the snippet you want to run (e. g. ddGetDocuments).
Valid values: string
Required
$params->params, (*148)
Desctription: Parameters that will be passed to the snippet constructor.
Valid values:
stdClass
arrayAssociative
stringJsonObject
stringQueryFormatted
Default value: —
$params->params->{$paramName}, (*149)
Desctription: Key is parameter name, value is value.
Valid values: mixed
Required
Examples
\ddTools::convertUrlToAbsolute($params): Convert relative URLs to absolute
$params->url can be set in various ways for more convenience:, (*150)
//Relative
$url = 'some/page?q=42#hash';
//Relative starting with slash
$url = '/some/page?q=42#hash';
//Absolute starting with domain
$url = 'example.com/some/page?q=42#hash';
//Absolute starting with double slash
$url = '//example.com/some/page?q=42#hash';
//Absolute starting with scheme
$url = 'https://example.com/some/page?q=42#hash';
\ddTools::convertUrlToAbsolute([
'url' => $url,
//The parameter is optional and is used here just for clarity. By default it will be equal to domain of your site.
'host' => 'example.com'
]);
Suppose we have the snippet ddSendFeedback with the getEmail and getId parameters.
Over time, we decided to rename the parameters as docField and docId respectively (as it happened in version 1.9).
And we want to save backward compatibility, the snippet must work with the old names and send message to the MODX event log., (*152)
//Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
$modx->getConfig('base_path') .
'assets/libs/ddTools/modx.ddtools.class.php'
);
//Backward compatibility
extract(\ddTools::verifyRenamedParams([
//We called the method inside of a snippet, so its parameters are contained in the `$params` variable (MODX feature)
'params' => $params,
'compliance' => [
//The new name => The old name
'docField' => 'getEmail',
'docId' => 'getId'
]
]));
Below we can use $docField and $docId and not to worry. The method will check everything and will send a message to the MODX event log., (*153)
After some time we decided to rename the parameters again as email_docField и email_docId. Nothing wrong, the method can works with multiple old names, just pass an array:, (*154)
extract(\ddTools::verifyRenamedParams([
//We called the method inside of a snippet, so its parameters are contained in the `$params` variable (MODX feature)
'params' => $params,
'compliance' => [
//The new name => The old names
'email_docField' => [
'docField',
'getEmail'
],
'email_docId' => [
'docId',
'getId'
]
],
//Also you can prevent writing to the CMS event log if you want
'writeToLog' => false
]));
\ddTools::parseText($params)
Basic example
\ddTools::parseText([
'text' => '
<article>
<h1>[+title+]</h1>
[+text+]
<p>[+authorFirstName+] [+authorLastName+], [+date+].</p>
</article>
',
'data' => [
'title' => 'Bethink Yourselves!',
'text' => '<p>Question your loyalty to your country and government and strive for a more just and peaceful society.</p>',
'authorFirstName' => 'Leo',
'authorLastName' => 'Tolstoy',
'date' => '1904'
]
]);
Returns:, (*155)
<article>
<h1>Bethink Yourselves!</h1>
<p>Question your loyalty to your country and government and strive for a more just and peaceful society.</p>
<p>Leo Tolstoy, 1904.</p>
</article>
Nested objects in $params->data
\ddTools::parseText([
//Data can have a complex nested structure
'data' => [
'title' => 'Bethink Yourselves!',
'text' => '<p>Question your actions and consider the morality behind them.</p>',
//Note that this is not a string, but that's okay
'meta' => [
//Moreover, any depth is supported
'author' => [
'firstName' => 'Leo',
'lastName' => 'Tolstoy',
],
'date' => '1904'
]
],
//For nested data you can use placeholders like '[+meta.date+]' for getting a property
//Or like '[+meta+]' to get whole object as JSON
'text' => '
<article data-meta=\'[+meta+]\'>
<h1>[+title+]</h1>
[+text+]
<p>[+meta.author.firstName+] [+meta.author.lastName+], [+meta.date+].</p>
</article>
'
]);
Returns:, (*156)
<article data-meta='{"author":{"firstName":"Leo","lastName":"Tolstoy"},"date":"1904"}'>
<h1>Bethink Yourselves!</h1>
<p>Question your actions and consider the morality behind them.</p>
<p>Leo Tolstoy, 1904.</p>
</article>
\DDTools\ObjectTools
\DDTools\ObjectTools::convertType($params)
Convert a JSON or Query encoded string to an array
For example, some snippet supports 2 formats in one of parameters: JSON or Query string.
Users use the format that is convenient to them and we support both.
Just call this method and don't care about it., (*157)
\DDTools\ObjectTools::convertType([
'object' => "{
//This is HJSON, not JSON, so we can use comments insides
keys: and values can be specified without quotes,
multilineValues:
'''
Write multiline strings with proper whitespace handling.
Starts and ends with triple quotes.
A simple syntax and easy to read.
'''
}",
'type' => 'objectStdClass'
]);
Returns:, (*161)
stdClass::__set_state(array(
'keys' => 'and values can be specified without quotes,',
'multilineValues' => 'Write multiline strings with proper whitespace handling.
Starts and ends with triple quotes.
A simple syntax and easy to read.',
))
Convert an associative array to a string of HTML attributes
No matter what type of element is used in any nesting level, the method will work fine.
So let's get Roger's name. As you remember, he is stdClass as opposed to the other members who are associative arrays., (*187)
Of course, it works fine with single-level objects that contain '.' in their property names
var_export(\DDTools\ObjectTools::getPropValue([
'object' => [
'1973.03.01' => 'The Dark Side of the Moon',
'1975.09.12' => 'Wish You Were Here'
],
'propName' => '1975.09.12'
]));
$collection->getItems([
//Spaces, tabs and line breaks are also allowed and do not matter
'filter' => '
gender == female ||
nobelPeacePrize == 1 && isHuman == 0
'
]);
array(
0 => stdClass::__set_state(array(
//Existing properties that absent in `$params->data` have remained as is
'name' => 'Mahatma Gandhi',
'isHuman' => 1,
'gender' => 'male',
//Given property values have overwritten the existing ones
'nobelPeacePrize' => 1,
//Non-existing properties have been created
'birthday' => '2 October 1869'
))
)