_evaluateControlFlowArrayElementRecursive($controlFlowElement); } } /** * @param array $controlFlowElement */ protected function _evaluateControlFlowArrayElementRecursive(array &$controlFlowElement) { $count = count($controlFlowElement); if(!is_array($controlFlowElement) || !($count > 0 && $count < 4)) { throw new \InvalidArgumentException('Every entry to the controlFlowArray must be an array with 3 entries: condition, iftrue, iffalse.'); } $condition = $controlFlowElement[0]; $ifTrueAction = (isset($controlFlowElement[1]) ? $controlFlowElement[1]:function(){}); $ifFalseAction = (isset($controlFlowElement[2]) ? $controlFlowElement[2]:function(){}); if(is_callable(($condition))) {$condition = $condition();} if((bool)$condition === true) { if(is_callable($ifTrueAction)) { $ifTrueAction(); } elseif(is_array($ifTrueAction)) { $this->_evaluateControlFlowArrayElementRecursive($ifTrueAction); }; } elseif((bool)$condition === false) { if(is_callable($ifFalseAction)) { $ifFalseAction(); } elseif(is_array($ifFalseAction)) { $this->_evaluateControlFlowArrayElementRecursive($ifFalseAction); } } } }