/** * Generator inner branches loop handler. * * @param Branch $branch Branch for looping its inner branches * @param bool $conditionStarted Return variable showing if inner branching has been started * @param string $pathValue Current routing logic $path variable name */ protected function generatorBranchesLoop(Branch $branch, &$conditionStarted, $pathValue) { // First stage - open condition // If we have started condition branching but this branch has parameters if ($conditionStarted && $branch->isParametrized()) { $this->generator->endIfCondition()->defIfCondition($branch->toLogicConditionCode($pathValue)); } elseif (!$conditionStarted) { // This is first inner branch // Start new condition $this->generator->defIfCondition($branch->toLogicConditionCode($pathValue)); // Set flag that condition has started $conditionStarted = true; } else { // This is regular branching $this->generator->defElseIfCondition($branch->toLogicConditionCode($pathValue)); } // Second stage receive parameters if ($branch->isParametrized()) { // Store parameter value received from condition $this->generator->newLine($branch->storeMatchedParameter()); } /** * Optimization to remove nested string operations - we create temporary $path variables */ $pathVariable = '$path' . mt_rand(0, 99999); // Do not output new $path variable creation if this is logic end if (count($branch->branches)) { $this->generator->newLine($pathVariable . ' = ' . $branch->removeMatchedPathCode($pathValue) . ';'); } // We should subtract part of $path var to remove this parameter // Go deeper in recursion $this->innerGenerate2($branch, $pathVariable, false); }