public function resolve() { $lastIndex = count($this->chain) - 1; do { $this->chain = array_values($this->chain); foreach ($this->chain as $index => $chainValue) { if ($chainValue instanceof ConditionJob) { if (!$chainValue->hasLastParameter() && $index < $lastIndex) { $parameter = $this->chain[$index + 1]; unset($this->chain[$index + 1]); $chainValue->setLastParameter($parameter); continue 2; } if (!$chainValue->hasFirstParameter() && $index > 0) { $parameter = $this->chain[$index - 1]; unset($this->chain[$index - 1]); $chainValue->setFirstParameter($parameter); continue 2; } } if ($chainValue instanceof Part) { $chainValue->resolve(); } } break; } while (true); parent::resolve(); }
public function resolve() { if ($this->firstParameter instanceof Part) { $this->firstParameter->resolve(); } if ($this->lastParameter instanceof Part) { $this->lastParameter->resolve(); } parent::resolve(); }
/** * Extracts part(s) of a (complicated) condition that map a column of the given table directly to a fixed value. * (E.g.: "(foo.a > bar.b && baz.c = 1) && (far.d = faz.e || far.f = 3)" results in "baz.c = 1" for table "baz") * * Only considers the parts that can directly negate the condition result (those liked with AND operators). * * @param ValuePart $condition * @return array (array of ValuePart) */ protected function findFixedConditions(Part $condition) { $tableConditions = array(); if ($condition instanceof ValuePart) { foreach ($condition->getChainValues() as $chainValue) { if ($chainValue instanceof Part) { $tableConditions = array_merge($tableConditions, $this->findFixedConditions($chainValue)); } } } elseif ($condition instanceof ConditionJob) { /* @var $condition ConditionJob */ if ($condition->getOperator() === Operator::OP_AND()) { foreach ([$condition->getFirstParameter(), $condition->getLastParameter()] as $conditionParameter) { if ($conditionParameter instanceof Part) { $tableConditions = array_merge($tableConditions, $this->findFixedConditions($conditionParameter)); } } } elseif (in_array($condition->getOperator(), [Operator::OP_EQUAL(), Operator::OP_EQUAL_NULLSAFE(), Operator::OP_NOT_EQUAL(), Operator::OP_GREATER(), Operator::OP_GREATEREQUAL(), Operator::OP_LESSER(), Operator::OP_LESSEREQUAL(), Operator::OP_BETWEEN(), Operator::OP_NOT_BETWEEN()])) { $column = $condition->getFirstParameter(); $fixedValue = $condition->getLastParameter(); if ($fixedValue instanceof ColumnSpecifier) { list($column, $fixedValue) = [$fixedValue, $column]; } if ($column instanceof ColumnSpecifier && $this->isFixedValue($fixedValue)) { $tableConditions[] = $condition; } } } return $tableConditions; }