Tests whether a context is valid for a hypercube
@param array|string $context A context ref or an array for a specific context
@param array $hypercube
@param boolean $closed
@return boolean
547046
public function isHypercubeDimensionallyValid( $context, $hypercube, $closed )
	{
		// Convert the array of dimensions into one indexed by qname as required by the isDimensionallyValid function
		$hypercubeDimensions = array_reduce( $hypercube['dimensions'], function( $carry, $dimension ) use( &$hypercubeDimensions )
		{
			$dimTaxonomy = $this->getInstanceTaxonomy()->getTaxonomyForXSD( $dimension['label'] );
			$element = $dimTaxonomy->getElementById( $dimension['label'] );

			$carry[ "{$dimTaxonomy->getPrefix()}:{$element['name']}" ] = $dimension;
			return $carry;
		}, array() );

		return $this->isDimensionallyValid( $context, $hypercubeDimensions, $closed );
	}
41176
public function evaluateContexts(array $provided = []) {

    $this->activeContexts = [];

    /** @var \Drupal\context\ContextInterface $context */
    foreach ($this->getContexts() as $context) {
      if ($this->evaluateContextConditions($context, $provided) && !$context->disabled()) {
        $this->activeContexts[$context->id()] = $context;
      }
    }

    $this->contextConditionsEvaluated = TRUE;
  }
689131
protected function isCircularReference($object, &$context)
    {
        $objectHash = spl_object_hash($object);

        $circularReferenceLimit = $context[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->circularReferenceLimit;
        if (isset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash])) {
            if ($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] >= $circularReferenceLimit) {
                unset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash]);

                return true;
            }

            ++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash];
        } else {
            $context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] = 1;
        }

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

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

        return $nbPositive > $nbNegative;
    }
433681
protected function evaluateNodeContext()
    {
        $eelContext = new Context($this->nodeContext);
        return $this->eelCompilingEvaluator->evaluate($this->getParsedMatcher(), $eelContext);
    }
12478
function handleContextNode( $context )
    {
        $contextName = null;
        $messages = array();
        $context_children = $context->childNodes;

        for( $i = 0; $i < $context_children->length; $i++ )
        {
            $context_child = $context_children->item( $i );
            if ( $context_child->nodeType == XML_ELEMENT_NODE )
            {
                if ( $context_child->tagName == "name" )
                {
                    $name_el = $context_child->firstChild;
                    if ( $name_el )
                    {
                        $contextName = $name_el->nodeValue;
                    }
                }
                break;
            }
        }
        if ( !$contextName )
        {
            eZDebug::writeError( "No context name found, skipping context", __METHOD__ );
            return false;
        }
        foreach( $context_children as $context_child )
        {
            if ( $context_child->nodeType == XML_ELEMENT_NODE )
            {
                $childName = $context_child->tagName;
                if ( $childName == "message" )
                {
                    $this->handleMessageNode( $contextName, $context_child );
                }
                else if ( $childName == "name" )
                {
                    /* Skip name tags */
                }
                else
                {
                    eZDebug::writeError( "Unknown element name: $childName", __METHOD__ );
                }
            }
        }
        if ( $contextName === null )
        {
            eZDebug::writeError( "No context name found, skipping context", __METHOD__ );
            return false;
        }
        if ( !isset( $this->CachedMessages[$contextName] ) )
            $this->CachedMessages[$contextName] = array();

        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] );
	}
122202
public function canEvaluate($context)
    {
        if (count($context) === 0) {
            return true;
        }

        foreach ($context as $contextNode) {
            if (!$contextNode instanceof NodeInterface) {
                return false;
            }
        }
        return true;
    }
902419
protected static function validate_contextlist_contexts(approved_contextlist $contextlist) {
        return array_reduce($contextlist->get_contexts(), function($carry, $context) {
            if ($context->contextlevel == CONTEXT_COURSE) {
                $carry[] = $context;
            }
            return $carry;
        }, []);
    }
535614
public function parse(ContextInterface $context, Cursor $cursor): bool
    {
        $container = $context->getContainer();

        // Replace paragraphs with tables
        if (!$container instanceof Paragraph) {
            return false;
        }

        $lines = $container->getStrings();

        $first_line = array_pop($lines);

        if (!preg_match(self::REGEX_CENSUS_TABLE_HEADER, $first_line)) {
            return false;
        }

        $head = $this->parseRow($first_line, TableCell::TYPE_HEAD);

        $table = new Table(function (Cursor $cursor) use (&$table): bool {
            $row = $this->parseRow($cursor->getLine(), TableCell::TYPE_BODY);
            if ($row === null) {
                return false;
            }
            $table->getBody()->appendChild($row);

            return true;
        });

        $table->getHead()->appendChild($head);
        $context->replaceContainerBlock($table);

        return true;
    }
173526
public function validate(\SwaggerValidator\Common\Context $context)
    {
        if (!$this->validateBaseSwagger($context)) {
            return false;
        }

        $keyPath = \SwaggerValidator\Common\FactorySwagger::KEY_PATHS;

        $context->logValidate(get_class($this), __METHOD__, __LINE__);
        $result = $this->$keyPath->validate($context->setDataPath($keyPath));

        if (!$result) {
            return false;
        }

        if ($context->getMode() === \SwaggerValidator\Common\Context::MODE_PASS) {
            $context->cleanParams();
            $context->setDataPath('CheckTooMany')->logValidate(get_class($this), __METHOD__, __LINE__);
            return true;
        }

        return $this->validateTooMany($context);
    }
1062133
protected function checkHost(\SwaggerValidator\Common\Context $context)
    {
        if (!isset($this->host)) {
            return true;
        }

        if ($context->getDataValue() === null) {
            return true;
        }

        if (strtolower($context->getDataValue()) && strtolower($this->host)) {
            return true;
        }

        return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_HOSTNAME_ERROR, 'HostName requested is not allowed', __METHOD__, __LINE__);
    }
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]);
	}
1340770
public function isDRSValidForFact( $fact,  $drs)
	{
		foreach ( $drs as $hypercube => $roles )
		{
			foreach ( $roles as $role => $hypercubeItems )
			{
				if ( ! isset( $hypercubes[ $hypercube ][ $role ] ) )
				{
					$closed = isset( $hypercubeItems['parents'][ $fact['label'] ]['closed'] ) && $hypercubeItems['parents'][ $fact['label'] ]['closed'];

					if ( ! $this->isHypercubeDimensionallyValid( $fact['contextRef'], $hypercubeItems, $closed ) ) continue;

					return true;
				}
			}
		}

		return false;
	}
222502
protected static function is_course_context_expired(\context $context) : bool {
        $expiryrecords = self::get_nested_expiry_info_for_courses($context->path);

        return !empty($expiryrecords[$context->path]) && $expiryrecords[$context->path]->info->is_fully_expired();
    }
1307919
protected static function _ref($context, $method)
    {
        if (is_string($context)) {
            return $context . "::{$method}";
        }
        return get_class($context) . '#' . spl_object_hash($context) . "::{$method}";
    }
533835
public function isValid($context = null)
    {
        // When there's an invalid data type, it should immediately report as invalid.
        if ($this->invalidDataTypeException !== null) {
            return false;
        }

        // When there's no data and the filter itself is not required,
        // it should immediately report as valid.
        if (!$this->data && !$this->isRequired()) {
            return true;
        }

        // Don't filter at all when "inputsToFilter" is set to empty array
        if (!$this->needsFiltering()) {
            return true;
        }

        return parent::isValid($context);
    }