Forward to logic

@param Context $context
@param $logic
@return Context
434939
public function forward(Context $context, $logic)
    {
        // resolve logic instance
        if(!$logic instanceof Logic) {

            // stored logic
            if(is_string($logic) and isset($this->logics[$logic])) {
                $logic = $this->logics[$logic];
            }
            // resolve callback
            else {
                $name = ($context->error instanceof HttpException) ? $context->error->getCode() : uniqid();
                $logic = Logic::resolve($name, $logic);
            }
        }

        $context->logic = $logic;
        return $this->proceed($context);
    }
817752
public function whereExp($field, $condition, $logic = 'and')
    {
        $this->parseWhereExp($logic, $field, 'exp', $condition);
        return $this;
    }
153019
public function createNewFromParent(Context $context, $parent)
    {
        $resource = $this->createNew($context);
        $resource->setParent($parent);
        return $resource;
    }
1172374
public static function translateContext(string $context, string $message, ...$args): string
    {
        $message = self::$translator->translateContext($context, $message);

        return sprintf($message, ...$args);
    }
1113195
public function setContext($context)
    {
        Assert::isTraversable($context);

        $this->context = MutableBag::from($context);

        return $this;
    }
351937
private function moreThanHalfConditionsHold(Context $context)
    {
        $nbPositive = 0;
        $nbNegative = 0;

        foreach ($this->conditions as $condition) {
            $condition->holdsFor($context) ? $nbPositive++ : $nbNegative++;
        }

        return $nbPositive > $nbNegative;
    }
20472
public function whereGroup($conditions, $logic = 'AND')
    {
        $whereGroup = $this->_append('Where_Group', $conditions, $logic);
        if ($group = $whereGroup->__toString()) {
            $this->where('(' . $group . ')', null, $logic);
        }

        return $this;
    }
1078319
protected function workOnInstance(Context $context)
    {
        $context = $context->setSerializeNull($this->setSerializeNull);

        // group override?
        if (true === $this->overrideHeaderAllowed &&
            $this->requestStack instanceof RequestStack &&
            $this->requestStack->getCurrentRequest() instanceof Request
        ) {
            $headerValue = $this->requestStack->getCurrentRequest()->headers->get($this->overrideHeaderName);
            if (!is_null($headerValue)) {
                $this->groups = array_map('trim', explode(',', $headerValue));
            }
        }

        $serializerGroups = [GroupsExclusionStrategy::DEFAULT_GROUP];
        if (is_array($this->groups) && !empty($this->groups)) {
            $serializerGroups = array_merge($serializerGroups, $this->groups);
        }

        foreach ($this->exclusionStrategies as $strategy) {
            $context->addExclusionStrategy($strategy);
        }

        return $context->setGroups($serializerGroups);
    }
675554
protected function getValueFromContext($rule, $context)
    {
        // Fields are only nested one level deep and flattened thereafter.
        $parts = explode('.', $rule->field);
        $key   = array_shift($parts);
        if (isset($context[$key]) && count($parts)) {
            $context = $context[$key];
            $key     = implode('.', $parts);
        } else {
            $key = $rule->field;
        }

        return isset($context[$key]) ? $context[$key] : false;
    }
441076
public function loadContext($context)
    {

        $ok = false;
        if (!empty($context->getRecordId())) {
            $sql = 'SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' .
                   "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' .
                   'WHERE (context_pk = :id)';
            $query = $this->db->prepare($sql);
            $query->bindValue('id', $context->getRecordId(), PDO::PARAM_INT);
        } else {
            $sql = 'SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' .
                   "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' .
                   'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
            $query = $this->db->prepare($sql);
            $query->bindValue('cid', $context->getConsumer()->getRecordId(), PDO::PARAM_INT);
            $query->bindValue('ctx', $context->ltiContextId, PDO::PARAM_STR);
        }
        $ok = $query->execute();
        if ($ok) {
          $row = $query->fetch(PDO::FETCH_ASSOC);
          $ok = ($row !== FALSE);
        }
        if ($ok) {
            $row = array_change_key_case($row);
            $context->setRecordId(intval($row['context_pk']));
            $context->setConsumerId(intval($row['consumer_pk']));
            $context->ltiContextId = $row['lti_context_id'];
            $context->type = $row['type'];
            $settings = unserialize($row['settings']);
            if (!is_array($settings)) {
                $settings = array();
            }
            $context->setSettings($settings);
            $context->created = strtotime($row['created']);
            $context->updated = strtotime($row['updated']);
        }

        return $ok;

    }
1355203
public function invoke($context, callable $next)
    {
        $messageId = $context->getMessageId();
        $physicalMessageContext = $this->incomingContextFactory->createPhysicalMessageContext($context);

        $deduplicationEntry = $this->outboxStorage->get($messageId);
        $pendingTransportOperations = $physicalMessageContext->getPendingTransportOperations();

        if (!$deduplicationEntry) {
            $this->outboxStorage->beginTransaction();

            try {
                $next($physicalMessageContext);

                $outboxOperations = $this->operationsConverter->convertToOutboxOperations($pendingTransportOperations);

                $outboxMessage = new OutboxMessage($messageId, $outboxOperations);
                $this->outboxStorage->store($outboxMessage);
                $this->outboxStorage->commit();
            } catch (\Throwable $t) {
                $this->outboxStorage->rollBack();
                throw $t;
            }
        } else {
            $pendingTransportOperations = $this->operationsConverter->convertToPendingTransportOperations(
                $deduplicationEntry
            );
        }

        $this->dispatchPendingOperations($pendingTransportOperations, $physicalMessageContext);

        $this->outboxStorage->markAsDispatched($messageId);
    }
1205522
public function resolve()
    {
        if (!$this->cached) {
            if (!($prev = $this->handler)) {
                throw new \LogicException('No handler has been specified');
            }

            foreach (array_reverse($this->stack) as $fn) {
                $prev = $fn[0]($prev);
            }

            $this->cached = $prev;
        }

        return $this->cached;
    }
1285053
def include_context(predicate, num, iterative):
    
    (it0, it1, it2) = itertools.tee(iterative, 3)
    psf = _forward_shifted_predicate(predicate, num, it1)
    psb = _backward_shifted_predicate(predicate, num, it2)
    return (e for (e, pf, pb) in zip(it0, psf, psb) if pf or pb)
720006
public function forward()
    {
        if ($this->position > count($this->stack) - 2) {
            throw new \LogicException('You are already on the last page.');
        }

        return clone $this->stack[++$this->position];
    }
293197
protected function ensureContext(OperationContextInterface $context = null)
    {
        if ($context === null) {
            $context = $this->getSession()->getDefaultContext();
        }

        return $context;
    }
439150
public function context($context, $value = null)
    {
        if (! is_array($context)) {
            $context = [$context => $value];
        }

        foreach ($context as $key => $value) {
            $this->context[$key] = $value;
        }

        return $this;
    }
760807
public function conditions($conditions, $context) {
		$path = null;
		if (isset($conditions['design'])) {
			$paths = ['design', 'view'];
			foreach ($paths as $element) {
				if (isset($conditions[$element])) {
					$path .= "_{$element}/{$conditions[$element]}/";
					unset($conditions[$element]);
				}
			}
		}
		if (isset($conditions['id'])) {
			$path = "{$conditions['id']}";
			unset($conditions['id']);
		}
		if (isset($conditions['path'])) {
			$path = "{$conditions['path']}";
			unset($conditions['path']);
		}
		return [$path, $conditions];
	}