dd/evolutioncms-snippets-ddobjecttools
Composer 安装命令:
composer require dd/evolutioncms-snippets-ddobjecttools
包简介
Tools for modifying objects.
关键字:
README 文档
README
Tools for modifying objects.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.62
Installation
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
//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
ddObjectToolsis not exist on your site,ddInstallerwill just install it. - If
ddObjectToolsis already exist on your site,ddInstallerwill check it version and update it if needed.
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddObjectTools. - Description:
<b>1.0</b> Tools for modifying objects.. - Category:
Core. - Parse DocBlock:
no. - Snippet code (php): Insert content of the
ddObjectTools_snippet.phpfile from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddObjectTools/. - Extract the archive to the folder (except
ddObjectTools_snippet.php).
Parameters description
-
sourceObject- Description: Source object or array.
- Valid values:
stringJsonObject— as JSONstringJsonArray— as JSONstringHjsonObject— as HJSONstringHjsonArray— as HJSONstringQueryFormatted— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet):arrayobject
- Default value:
'{}'
-
extend- Description: Merge the contents of two or more objects / arrays together into
sourceObject(it will receive the new properties). - Valid values:
stringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormatted— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet):arrayAssociativeobject
- Default value: —
- Description: Merge the contents of two or more objects / arrays together into
-
extend->objects- Description: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
- Valid values:
arraystringJsonArray— as JSONstringHjsonArray— as HJSONstringQueryFormatted— as Query string
- Required
-
extend->objects[i]- Description: An object or array containing additional properties to merge in.
- Valid values:
objectarray
- Required
-
extend->deep- Description: If true, the merge becomes recursive (aka “deep copy”).
- Valid values:
boolean - Default value:
true
-
extend->overwriteWithEmpty- Description: 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
- Description: Overwrite fields with empty values.
-
getPropValue- Description: This parameter allows you to return required property of an object.
- Valid values:
string— just name of a property or array index / key to return, use asgetPropValue->namein this case- An object of additional parameters:
stringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormatted— as Query string- It can also be set as native PHP object or array (e. g. for calls through
\DDTools\Snippet::runSnippetor$modx->runSnippet):arrayAssociativeobject
- Default value: —
-
getPropValue->name- Description: Object property name or array index / key to return.
You can also use'.'to get nested properties (see\DDTools\ObjectTools::getPropValuefor more info). - Valid values:
string - Required
- Description: Object property name or array index / key to return.
-
getPropValue->notFoundResult- Description: What will be returned when the property is not found.
- Valid values:
mixed - Default value:
null
-
outputter- Description: Output format (when result is an object or array).
Values are case insensitive (the following values are equal:'stringjsonauto','stringJsonAuto','STRINGJSONAUTO', etc). - Valid values:
- The snippet can return object as string:
'stringJsonAuto'—stringJsonObjectorstringJsonArraydepends on result object'stringJsonObject''stringJsonArray''stringQueryFormatted'— Query string
- The snippet can also return object as a native PHP object or array (it is convenient to call through
\DDTools\Snippet).'objectAuto'—stdClassorarraydepends on result object'objectStdClass'—stdClass'objectArray'—array
- The snippet can return object as string:
- Default value:
'stringJsonAuto'
- Description: Output format (when result is an object or array).
Examples
All examples are written using HJSON, but if you want you can use vanilla JSON instead.
Merge the contents of two or more objects together into the first object (the extend parameter)
[[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
}
Get an object property
[[ddObjectTools?
&sourceObject=`{
firstName: Chuck
lastName: Norris
}`
&getPropValue=`firstName`
]]
Returns: Chuck.
Custom results when the property is not found
[[ddObjectTools?
&sourceObject=`{
firstName: Viktor
lastName: Tsoi
dates: {
born: 1962.06.21
}
}`
&getPropValue=`{
name: dates.death
notFoundResult: forever alive
}`
]]
Returns: forever alive.
Get an array element
[[ddObjectTools?
&sourceObject=`[
Pink Floyd
The Beatles
Queen
]`
&getPropValue=`2`
]]
Returns: Queen.
Convert a JSON object to an array
[[ddObjectTools?
&sourceObject=`{
firstName: Angus
lastName: Young
}`
&outputter=`jsonArray`
]]
Returns:
[ "Angus", "Young" ]
Run the snippet through \DDTools\Snippet::runSnippet without DB and eval
//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
dd/evolutioncms-snippets-ddobjecttools 适用场景与选型建议
dd/evolutioncms-snippets-ddobjecttools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「objects」 「modx」 「MODX Evo」 「evo」 「modx evolution」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dd/evolutioncms-snippets-ddobjecttools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dd/evolutioncms-snippets-ddobjecttools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dd/evolutioncms-snippets-ddobjecttools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Provides Symfony param converters for mediagone/types-common package.
This package provides all of CFX's public data objects.
Simple ORM for PHP, using your already existing structure, no command line required!
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-05-08