dd/evolutioncms-snippets-ddif 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dd/evolutioncms-snippets-ddif

Composer 安装命令:

composer require dd/evolutioncms-snippets-ddif

包简介

This snippet compares different values and returns required chunk or string.

README 文档

README

This snippet compares different values and returns required chunk or string.

Requires

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.ddIf
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddIf',
	'type' => 'snippet'
]);
  • If ddIf is not exist on your site, ddInstaller will just install it.
  • If ddIf is already exist on your site, ddInstaller will check it version and update it if needed.

Manually

1. Elements → Snippets: Create a new snippet with the following data

  1. Snippet name: ddIf.
  2. Description: <b>2.3.1</b> This snippet compares different values and returns required chunk or string..
  3. Category: Core.
  4. Parse DocBlock: no.
  5. Snippet code (php): Insert content of the ddIf_snippet.php file from the archive.

2. Elements → Manage Files

  1. Create a new folder assets/snippets/ddIf/.
  2. Extract the archive to the folder (except ddIf_snippet.php).

Parameters description

  • operand1

    • Desctription: The first operand for comparing.
      An empty unparsed placeholder (like '[+somePlaceholder+]') will be interpretated as empty string ('').
    • Valid values: string
    • Required
  • operand2

    • Desctription: The second operand for comparing.
    • Valid values: string
    • Default value: ''
  • operator

    • Desctription: Comparing operator.
      Values are case insensitive (the following names are equal: 'isNumeric', 'isnumeric', 'ISNUMERIC', etc).
    • Valid values:
      • '=='
      • '!='
      • '>'
      • '<'
      • '<='
      • '>='
      • 'bool'
      • 'inArray'
      • 'isNumeric'
      • 'isWhitespace' — checks if operand1 is just white space (an empty string is also considered as white space)
      • 'isIncludes' — case-sensitive check if operand1 contains operand2
    • Default value: '=='
  • trueChunk

    • Desctription: This value is returning if result is true. Available placeholders:
      • [+ddIfParams.operand1+] — contains operand1 value.
      • [+ddIfParams.operand2+] — contains operand2 value.
      • [+ddIfParams.operator+] — contains operator value.
      • [+any placeholders from the placeholders parameter+]
    • Valid values:
      • stringChunkName
      • string — use inline templates starting with @CODE:
    • Default value: ''
  • falseChunk

    • Desctription: This value is returning if result is false. Available placeholders:
      • [+ddIfParams.operand1+] — contains operand1 value.
      • [+ddIfParams.operand2+] — contains operand2 value.
      • [+ddIfParams.operator+] — contains operator value.
      • [+any placeholders from the placeholders parameter+]
    • Valid values:
      • stringChunkName
      • string — use inline templates starting with @CODE:
    • Default value: ''
  • placeholders

    • Desctription: Additional data has to be passed into the trueChunk and falseChunk.
      Nested objects and arrays are supported too:
      • {"someOne": "1", "someTwo": "test" } => [+someOne+], [+someTwo+].
      • {"some": {"a": "one", "b": "two"} } => [+some.a+], [+some.b+].
      • {"some": ["one", "two"] } => [+some.0+], [+some.1+].
    • Valid values:
      • stringJsonObject — as JSON
      • stringHjsonObject — as HJSON
      • stringQueryFormatted — as Query string
      • It can also be set as a native PHP object or array (e. g. for calls through $modx->runSnippet):
        • arrayAssociative
        • object
    • Default value: —
  • debugTitle

    • Desctription: The title for the System Event log if debugging is needed.
      Just set it and watch the System Event log.
    • Valid values: string
    • Default value: —

Examples

String comparison

[[ddIf?
	&operand1=`Test string 1`
	&operator=`==`
	&operand2=`Test string 2`
	&trueChunk=`@CODE:The strings are equal.`
	&falseChunk=`@CODE:The strings are not equal.`
]]

Returns:

The strings are not equal.

Checks if a value exists in an array

[[ddIf?
	&operand1=`Apple`
	&operator=`inArray`
	&operand2=`Pear,Banana,Apple,Orange`
	&trueChunk=`@CODE:Exists.`
	&falseChunk=`@CODE:Not exists.`
]]

Returns:

Exists.

Check if operand1 contains operand2

[[ddIf?
	&operand1=`The quick brown fox jumps over the lazy dog.`
	&operator=`isIncludes`
	&operand2=`fox`
	&trueChunk=`@CODE:“fox” is found`
	&falseChunk=`@CODE:“fox” is not found`
]]

Returns:

“fox” is found

Checks if a operand1 value is number or not

[[ddIf?
	&operand1=`123`
	&operator=`isNumeric`
	&trueChunk=`@CODE:Number.`
	&falseChunk=`@CODE:Not number.`
]]

Returns:

Number.

Checks if a operand1 value is just white space or not

Any number of spaces / tabs / new lines / etc are considered as white space. An empty string is also considered as white space.

[[ddIf?
	&operand1=`
		 
	   
	    
	`
	&operator=`isWhitespace`
	&trueChunk=`@CODE:The string contains only some whitespace characters.`
	&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]

Returns:

The string contains only some whitespace characters.

If operand1 contains any non-whitespace characters, falseString will be returned.

[[ddIf?
	&operand1=`All you need is love.`
	&operator=`isWhitespace`
	&trueChunk=`@CODE:The string contains only some whitespace characters.`
	&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]

Returns:

All you need is love.

Number comparison and pass additional data to chunks

[[ddIf?
	&operand1=`[*general_price*]`
	&operator=`<`
	&operand2=`500`
	&trueChunk=`general_goodInexpensive`
	&falseChunk=`general_good`
	&placeholders=`{
		"title": "[*pagetitle*]",
		"image": "[*general_image*]",
		"somethingText": "All we need is love!"
	}`
]]

Code of the general_good chunk:

<div>
	<h2>[+title+], $[+ddIfParams.operand1+]</h2>
	<img src="[+image+]" alt="[+title+]" />
</div>

Code of the general_goodInexpensive chunk:

<div class="inexpensive">
	<h2>[+title+], <strong>$[+ddIfParams.operand1+]</strong></h2>
	<img src="[+image+]" alt="[+title+]" />
	<p>[+somethingText+]</p>
</div>

Let [*general_price*] be equal to 120, then the snippet returns:

<div class="inexpensive">
	<h2>Some inexpensive good, <strong>$120</strong></h2>
	<img src="assets/images/goods/some1.jpg" alt="Some inexpensive good" />
</div>

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.ddIf
\DDTools\Snippet::runSnippet([
	'name' => 'ddIf',
	'params' => [
		'operand1' => '1',
		'operator' => 'bool',
		'trueChunk' => '@CODE:It's true!'
	]
]);

Links

dd/evolutioncms-snippets-ddif 适用场景与选型建议

dd/evolutioncms-snippets-ddif 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「compare」 「modx」 「MODX Evo」 「evo」 「modx evolution」 「if」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dd/evolutioncms-snippets-ddif 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dd/evolutioncms-snippets-ddif 我们能提供哪些服务?
定制开发 / 二次开发

基于 dd/evolutioncms-snippets-ddif 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-09-28