PHP code example of andydune / conditional-execution
1. Go to this page and download the library: Download andydune/conditional-execution library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
andydune / conditional-execution example snippets
if ((empty($arParams["PAGER_PARAMS_NAME"]) || !preg_match("/^[A-Za-z_][A-Za-z01-9_]*$/", $arParams["PAGER_PARAMS_NAME"]))
&& $arParams["SECTION_ID"] > 0 && $arParams["SECTION_ID"]."" != $arParams["~SECTION_ID"]
)
{
// some php code
// fuction call or method
}
use AndyDune\ConditionalExecution\ConditionHolder;
$instanceOr = new ConditionHolder();
$instanceOr->bindOr()
->add(empty($arParams["PAGER_PARAMS_NAME"]))
->add(!preg_match("/^[A-Za-z_][A-Za-z01-9_]*$/", $arParams["PAGER_PARAMS_NAME"]));
$instanceTotal = = new ConditionHolder(); // default bind AND
$instanceTotal->executeIfTrue(function(){
// some php code
// fuction call or method
});
$instanceTotal->add($instanceOr)
->add($arParams["SECTION_ID"] > 0)
->add($arParams["SECTION_ID"]."" != $arParams["~SECTION_ID"]);
$result = $instanceTotal->doIt(); // yes, do it!
use AndyDune\ConditionalExecution\Check\ArrayValueWithKeyNotEmpty;
use AndyDune\ConditionalExecution\ConditionHolder;
// Source array
$array = [
'one' => 1
];
$condition = new ConditionHolder();
$condition->add(new ArrayValueWithKeyNotEmpty('one'));
$condition->check($array); // result is true
$condition->setNegative();
$condition->check($array); // result is false
use AndyDune\ConditionalExecution\Check\ArrayHasNotEmptyValueOrKeyNotExist;
use AndyDune\ConditionalExecution\ConditionHolder;
$array = [
'one' => 1,
'two' => '',
'three' => 0
];
$condition = new ConditionHolder();
$condition->add(new ArrayHasNotEmptyValueOrKeyNotExist('one'))->check($array); // true
$condition = new ConditionHolder();
$condition->add(new ArrayHasNotEmptyValueOrKeyNotExist('two'))->check($array); // false
$condition = new ConditionHolder();
$condition->add(new ArrayHasNotEmptyValueOrKeyNotExist('three'))->check($array); // false
$condition = new ConditionHolder();
$condition->add(new ArrayHasNotEmptyValueOrKeyNotExist('four'))->check($array); // true