/** * Solve the group context. * * @param string $logical * @param bool $negation * * @return Builder */ protected function solveContext($logical, $negation) { if ($this->group->getOperator() !== $logical) { // If the current group operator is different from the requested // spawn a new group and nest the current one $group = GroupFactory::build($logical); $this->group->nest($group); $this->group = $group; } if ($negation) { // Create a new ! group, push it without clone and return to // build query on it. $context = GroupFactory::build('!'); $group = GroupFactory::build(); $context->push($group, false); $this->group->push($context, false); return $group; } return $this->group; }
/** * Nest this Group to provided parent. * * @param Group $parent * * @return void */ public function nest(Group $parent) { $parent->push($this); }