@param Context $context

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

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

        return $nbPositive > $nbNegative;
    }
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);
    }
372605
protected function failedAction(Context $context)
    {
        $input = function () use ($context) {
            return [$context];
        };

        return $this->newInstance(
            $input,
            [$this->matcher, 'getName'],
            $this->failResponder
        );
    }
520377
public function isValid($value, $context = null)
    {
        $this->_setValue((string) $value);

        if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) {
            $token = $context[$this->getToken()];
        } else {
            $token = $this->getToken();
        }

        if ($token === null) {
            $this->_error(self::MISSING_TOKEN);
            return false;
        }

        $strict = $this->getStrict();
        if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) {
            $this->_error(self::NOT_SAME);
            return false;
        }

        return true;
    }
1047405
public function evaluate(Context $context)
    {
        /** @var Proposition $operand */
        foreach ($this->getOperands() as $operand) {
            if ($operand->evaluate($context) === true) {
                return true;
            }
        }

        return false;
    }
1171164
private function initializeInstance(Context $context)
    {
        foreach ($this->contextInitializers as $initializer) {
            $initializer->initializeContext($context);
        }
    }
704970
public function bind(Context $context)
    {
        if (! isset($context->__UBID)) {
            $context->__UBID = 0;
        }
        $context->__UBID ++;
        
        return spl_object_hash($context) . $context->__UBID;
    }
970880
public function initializeContext(Context $context)
    {
        if (!$context instanceof MinkAwareContext) {
            return;
        }

        $context->setMink($this->mink);
        $context->setMinkParameters($this->parameters);
    }
1204734
public function evaluate( Context $context ) {
		/* @var \Ruler\Variable $left */
		list( $left ) = $this->getOperands();

		return null === $left->prepareValue( $context )->getValue();
	}
669920
public function filter(Context $context)
    {
        $this->index++;
        if(empty($this->m_filters) || $this->index >= count($this->m_filters))
            return;
        $filter=$this->m_filters[$this->index];
        return $filter->filter($context,$this);
    }
400416
public function getContextLocale($context)
    {
        return isset($this->contextLocales[$context]) ? $this->contextLocales[$context] : null;
    }
622809
protected function _authorizeEdit($context)
    {
        if ($this->_viewer->guest()) {
            return false;
        }

        if ($this->_viewer->admin()) {
            return true;
        }

        if ($this->_viewer->eql($this->_entity->author)) {
            return true;
        }

        //if the viewer is the admin of the medium owner
        if (
            $this->_entity->isOwnable() &&
            $this->_entity->owner->authorize('administration')) {
            return true;
        }

        return false;
    }
974463
protected function is_needed( $context = null ) {

		$is_needed = $this->hasConfigKey( 'is_needed' )
			? $this->getConfigKey( 'is_needed' )
			: true;

		if ( is_callable( $is_needed ) ) {
			return $is_needed( $context );
		}

		return (bool) $is_needed;
	}
121836
protected function isSafe($context)
	{
		// Test this attribute's filters
		$methodName = 'isSafe' . $context;
		foreach ($this->filterChain as $filter)
		{
			if ($filter->$methodName())
			{
				// If any filter makes it safe, we consider it safe
				return true;
			}
		}

		return !empty($this->markedSafe[$context]);
	}
211142
private function evalCondition(Context $context) {
		return (null !== $this->figCond) ? $this->evaluate($context, $this->figCond) : true;
	}
38022
public function parse(Context $context) {
	    $this->context = $context;
		$this->viewElement = $context->tag;

		//Interpret an empty expression as boolean false.
		if(trim($this->expression) == '') {
		  $this->pushOperand(new TokenLiteral(false));
		  return true;
		}

		$char = '';

		try {
			$expressionSize = strlen($this->expression);
			for($this->parsingPosition = 0; $this->parsingPosition < $expressionSize; ++ $this->parsingPosition) {
				$char = $this->expression[$this->parsingPosition];
				$this->currentState->input($this, $char);
			}

			$this->currentState->endOfInput($this);

			while(count($this->stackOperators)) {
				$operator = array_pop($this->stackOperators);
				$nbOperands = $operator->getNumOperands();
				if($nbOperands) {
					// Check that we have enough operands on the stack.
					if (count($this->stackRP) < $nbOperands) {
						throw new LexerSyntaxErrorException('Missing operand', $this->getViewFile(), $this->getViewLine());
					}
					$operator->setOperands(array_splice($this->stackRP, count($this->stackRP) - $nbOperands, $nbOperands));
				}
				$this->stackRP[] = $operator;
				if($operator instanceof TokenFunction) {
									array_pop($this->stackFunctions);
				}
			}
		}

		// Enrich the Lexer parsing and tokenizing exceptions with template file and line
		catch (LexerUnbalancedParenthesesException $exception) {
		    throw new LexerUnbalancedParenthesesException($exception->getMessage(), $this->getViewFile(), $this->getViewLine());
        } catch (LexerSyntaxErrorException $exception) {
		    throw new LexerSyntaxErrorException($exception->getMessage(), $this->getViewFile(), $this->getViewLine());
        } catch (Exception $exception) {
			$errorMsg = "Unexpected character: $char at position: {$this->parsingPosition} in expression: {$this->expression}.";
			throw new LexerUnexpectedCharException($errorMsg, $this->getViewFile(), $this->getViewLine());
		}

		if( (count($this->stackOperators) > 0) ||
				(count($this->stackFunctions) > 0) ||
				(count($this->stackRP) != 1)
			)
		{
			$message = $this->getViewFile() . '(' . $this->getViewLine() . '): Syntax error in expression: ' . $this->expression;
			throw new LexerSyntaxErrorException($message,
					$this->getViewFile(),
					$this->getViewLine());
		}

		// Check for unbalanced parentheses:
		if( ($this->stackRP[0] instanceof TokenFunction) &&
		    (! $this->stackRP[0]->isClosed())
		)
		{
		  $message = $this->getViewFile() . '(' . $this->getViewLine() . '): Unbalanced parentheses in expression: ' . $this->expression;
		  throw new LexerUnbalancedParenthesesException($message,
		    $this->getViewFile(),
		    $this->getViewLine());
		}

		return true;
	}
659090
public function evaluate( Context $context ) {
		/**
		 * Extracts variables.
		 *
		 * @var \Ruler\Variable $left
		 * @var \Ruler\Variable $right
		 */
		list( $left, $right ) = $this->getOperands();

		$left  = $left->prepareValue( $context )->getValue();
		$right = $right->prepareValue( $context )->getValue();

		if ( 2 !== count( $right ) ) {
			return false;
		}

		// Make sure we have a valid range.
		if ( $right[0] > $right[1] ) {
			$temp     = $right[0];
			$right[0] = $right[1];
			$right[1] = $temp;
		}

		return ( $left >= $right[0] && $left <= $right[1] );
	}