Called by parse, loops through all the rules to find out if nested or not.

@param array  $rules
@param array  $context
@param string $condition

@return bool

@throws Exception
@throws \Exception
327072
protected function loopThroughRules(array $rules, array $context = [], $condition = 'AND')
    {
        $result    = true;
        $condition = strtolower($condition);
        $this->validateCondition($condition);
        foreach ($rules as $rule) {
            $result = $this->evaluate($rule, $context);
            if ($result && $this->isNested($rule)) {
                $result = $this->loopThroughRules($rule->rules, $context, $condition);
            }
            // Conditions upon which we can stop evaluation.
            if ('and' == $condition && !$result) {
                break;
            } else {
                if ('or' == $condition && $result) {
                    break;
                }
            }
        }

        return $result;
    }
1190308
protected function processConditions()
    {
        $data = $this->getData();
        $conditions = $this->_conditions;
        $result = array_filter($data, function ($val) use ($conditions) {
            $res = false;
            foreach ($conditions as $cond) {
                $tmp = true;
                foreach ($cond as $rule) {
                    $function = self::$_rulesMap[$rule['condition']];
                    if (!is_callable($function)) {
                        if (!method_exists(Condition::class, $function)) {
                            throw new ConditionNotAllowedException("Exception: $function condition not allowed");
                        }
                        
                        $function = [Condition::class, $function];
                    }
                    
                    $value = $this->getFromNested($val, $rule['key']);
                    $return = $value instanceof ValueNotFound ? false :  call_user_func_array($function, [$value, $rule['value']]);
                    $tmp &= $return;
                }
                $res |= $tmp;
            }
            return $res;
        });

        return $result;
    }
255200
public function setRules(array $rules)
    {
        $this->rules = [];

        foreach ($rules as $rule) {
            $controller  = strtolower($rule['controller']);
            $actions     = isset($rule['actions']) ? (array)$rule['actions'] : [];
            $permissions = (array)$rule['permissions'];

            if (empty($actions)) {
                $this->rules[$controller][0] = $permissions;
                continue;
            }

            foreach ($actions as $action) {
                $this->rules[$controller][strtolower($action)] = $permissions;
            }
        }
    }
778809
public function addRules($rules)
    {
        foreach ($rules as $rule) {
            $this->addrule($rule[0], $rule[1], $rule[2], isset($rule[3])?$rule[3]:null);
        }
    }
173568
public function filter($json, array $context = [])
    {
        $query = $this->decodeJSON($json);
        if (!isset($query->rules) || !is_array($query->rules) || count($query->rules) < 1) {
            $this->setError('No rules to evaluate.');

            return false;
        }

        return $this->loopThroughRules($query->rules, $context, isset($query->condition) ? $query->condition : 'AND');
    }
1302304
public function handle(\ErrorException $exception, array $context)
    {
        $levels = array_flip($this->sevirity);
        $sevirity = $exception->getSeverity();

        if (!in_array($sevirity, $levels)) {
            $sevirity = 9802;
        }
        $sevirities = array_slice($levels, $levels[$this->level] - 9809, null, true);

        if (!array_key_exists($this->sevirity[$sevirity], $sevirities) || array_shift($sevirities) == $levels[$this->sevirity[$sevirity]]) {

            $context['exception'] = $exception;
            $this->{$this->sevirity[$sevirity]}($exception->getMessage(), $context);
        } else {
            return false;
        }
        return true;
    }
577769
public function parse($rules)
    {
        $attributes = array();
        $rules = $rule = $this->getRulesAsArray($rules);

        foreach ($rules as $rule) {
            list($rule, $parameters) = $this->parseRule($rule);

            if ($rule && method_exists($this, $rule)) {
                $attributes += $this->$rule($parameters);
            }
        }

        return $attributes;
    }
550798
public function nestedResource(array $conditions)
    {
        foreach ($this->_nestedResources as $url => $options) {
            if (count(array_intersect_key(array_flip($options['requiredFields']), $conditions)) !== count($options['requiredFields'])) {
                continue;
            }

            return Text::insert($url, $conditions);
        }

        return false;
    }
811599
public function addRules($rules, $append = true)
    {
        foreach ($rules as $key => $rule) {
            if (is_array($rule) && isset($rule['composition'])) {
                foreach ($rule['composition'] as $composition => $pattern) {
                    $rules[] = [
                        'pattern' => $pattern,
                        'route' => $composition.'/'.$rule['route'],
                    ];
                }
            }
        }

        return parent::addRules($rules, $append);
    }
1278161
public function used(array $condition, array $data)
    {
        if (!isset($data['rule']['used'])) {
            return false;
        }

        return $this->compare($data['rule']['used'], $condition['value'], $condition['operator']);
    }
387273
public function setRules(array $rules): self
    {
        assert(empty($rules) === false);

        $this->rules = $rules;

        return $this;
    }
157491
public function checkContext(ContextInterface $context)
    {
        try {
            $checkedCode = $this->preprocessor->preprocess($context->getCheckedCode());
            $parsedStatements = $this->parser->parse($checkedCode);
            $this->traverser->traverse($parsedStatements, $context, $this->lexer->getTokens());
        } catch (\Exception $e) {
            $context->addError(new CheckError($e->getMessage()));
        } catch (\ParseException $e) {
            $context->addError(new CheckError($e->getMessage(), $e->getLine()));
        }
    }
289007
public function setConditions(array $conditions = [])
    {
        $this->conditions = $conditions;

        $this->condition = $this->parseCondition($this->uri());
        $this->conditionParams = $this->parseConditionParams($this->getAction());

        return $this;
    }
126646
public static function parse_css_rules( array $rules ) {

		ob_start();

		foreach ( $rules as $rule => $properties ) {

			printf(
				"%s {\n",
				implode( ",\n", array_map( 'trim', explode( ',', $rule ) ) )
			);

			foreach ( $properties as $property => $value ) {

				printf( "\t%s: %s;\n", $property, $value );

			}

			echo "}\n";

		}

		return ob_get_clean();

	}
287827
public static void build(final RuleBuildContext context) {
        RuleDescr ruleDescr = context.getRuleDescr();

        final RuleConditionBuilder builder = (RuleConditionBuilder) context.getDialect().getBuilder( ruleDescr.getLhs().getClass() );
        if ( builder != null ) {
            Pattern prefixPattern = context.getPrefixPattern(); // this is established during pre-processing, if it's query
            final GroupElement ce = (GroupElement) builder.build( context,
                                                                  getLhsForRuleUnit( context.getRule(), ruleDescr.getLhs() ),
                                                                  prefixPattern );

            context.getRule().setLhs( ce );
        } else {
            throw new RuntimeException( "BUG: builder not found for descriptor class " + ruleDescr.getLhs().getClass() );
        }

        // build all the rule's attributes
        // must be after building LHS because some attributes require bindings from the LHS
        buildAttributes( context );

        // Build the consequence and generate it's invoker/s
        // generate the main rule from the previously generated s.
        if ( !(ruleDescr instanceof QueryDescr) ) {
            // do not build the consequence if we have a query

            ConsequenceBuilder consequenceBuilder = context.getDialect().getConsequenceBuilder();
            consequenceBuilder.build( context, RuleImpl.DEFAULT_CONSEQUENCE_NAME );
            
            for ( String name : ruleDescr.getNamedConsequences().keySet() ) {
                consequenceBuilder.build( context, name );
            }
        }
    }
1274152
public function addRules(array $rules) : ValidatorInterface
    {
        if (!is_array($rules) || empty($rules)) {
            throw new ValidatorException(sprintf('Validator::addRules() expect array of rules, %s given.', \gettype($rules)));
        }

        foreach ($rules as $field => $rule) {
            $this->addRule($field, $rule);
        }

        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];
	}