Validate the contents of an access rule.

@param array $rule Access rule to check
@throws RuntimeException
555843
private function validateRule(EventInterface $event, array $rule) {
        $acl = $event->getAccessControl();

        $allowedProperties = ['resources', 'group', 'users'];
        $unknownProperties = array_diff(array_keys($rule), $allowedProperties);

        if (!empty($unknownProperties)) {
            throw new RuntimeException('Found unknown properties in rule: [' . implode(', ', $unknownProperties) . ']', 400);
        }

        if (isset($rule['resources']) && isset($rule['group'])) {
            throw new RuntimeException('Both resources and group found in rule', 400);
        }

        if (!isset($rule['resources']) && !isset($rule['group'])) {
            throw new RuntimeException('Neither group nor resources found in rule', 400);
        }

        if (isset($rule['resources']) && !$this->isStringArray($rule['resources'])) {
            throw new RuntimeException('Illegal value in resources array. String array expected', 400);
        }

        if (isset($rule['group'])) {
            if (!is_string($rule['group'])) {
                throw new RuntimeException('Group must be specified as a string value', 400);
            }

            if (!$acl->getGroup($rule['group'])) {
                throw new RuntimeException('Group \'' . $rule['group'] . '\' does not exist', 400);
            }
        }

        if (!isset($rule['users'])) {
            throw new RuntimeException('Users not specified in rule', 400);
        }

        if ($rule['users'] !== '*' && !$this->isStringArray($rule['users'])) {
            throw new RuntimeException('Illegal value for users property. Allowed: \'*\' or array with users', 400);
        }
    }
986961
protected function setRules( array $rules )
	{
		foreach( $rules as $key => $rule ) {
			$rules[ $key ] = is_string( $rule ) ? explode( '|', $rule ) : $rule;
		}

		$this->rules = $rules;

		return $this;
	}
358585
private function extractNeededProperties($rule)
    {
        if (\in_array($rule['operation'], ['AND', 'OR'])) {
            $properties = [];
            foreach ($rule['children'] as $childRule) {
                $properties[] = $this->extractNeededProperties($childRule);
            }
            return $properties;
        }

        // Local is child property name.
        if (isset($rule['local'])) {
            return $rule['local'];
        }

        // Remote is parent property name.
        if (isset($rule['property'])) {
            return $rule['property'];
        }

        throw new \RuntimeException('Unexpected filter rule ' . \var_export($rule, true));
    }
171733
private function validateRule($rule): bool
    {
        if ($rule instanceof \Closure || $rule instanceof RuleInterface) {
            return true;
        }

        if (is_array($rule)) {
            return is_callable($rule, true);
        }

        if (is_string($rule) && class_exists($rule)) {
            try {
                $reflection = new \ReflectionClass($rule);
            } catch (\ReflectionException $e) {
                return false;
            }

            return $reflection->isSubclassOf(RuleInterface::class);
        }

        return false;
    }
1251762
protected function validateField(string $field, string $rule): bool
	{
		$parsedRule = $this->parseRule($rule);

		$rule = $this->ruleFactory($parsedRule->name, $parsedRule->parameters);

		// Just return true if the input field is empty and the rule doesn't validate empty input

		if($this->isInputFieldEmpty($inputValue = Arr::get($this->input, $field)) && $rule->validateWhenEmpty() === false)
		{
			return true;
		}

		// Validate input

		if($rule->validate($inputValue, $this->input) === false)
		{
			$this->errors[$field] = $this->getErrorMessage($rule, $field, $parsedRule);

			return $this->isValid = false;
		}

		return true;
	}
513981
public function addRules(array $rules)
    {
        foreach ($rules as $character => $replacement) {
            $this->addRule($character, $replacement);
        }

        return $this;
    }
634523
public function validate($rule, $value)
    {
        $arguments = $this->buildArgumentArray($rule, $value);

        $method = $this->makeRuleMethod($rule);

        if ($this->userDefinedExists($method)) {
            $class = NameResolver::makeRulesFileName();

            return call_user_func_array([$class, $method], $arguments);
        } elseif (method_exists(Rules::class, $method)) {
            return call_user_func_array([Rules::class, $method], $arguments);
        }

        throw InvalidSettingsRule::ruleNotFound($rule, $method);
    }
720890
public function collectRule(Rule $rule): void
    {
        $this->data['rule'] = [
            'id' => $rule->getId(),
        ];

        foreach ($rule->getTargets() as $target) {
            $this->data['rule']['targets'][] = [
                'type' => $target->getTargetType()::getType(),
                'value' => $this->formatVar($target->getValue()),
            ];
        }

        foreach ($rule->getConditions() as $condition) {
            $this->data['rule']['conditions'][] = [
                'type' => $condition->getConditionType()::getType(),
                'value' => $this->formatVar($condition->getValue()),
            ];
        }
    }
692859
public function mapFieldsRules(array $rules)
    {
        foreach ($rules as $field => $rule) {
            $this->mapFieldRules($field, $rule);
        }
    }
1368639
public function & rules(array $rules){
      foreach ((array)$rules as $varname => $rule){
        $this->rules[$varname] = $rule;
      }
      $this->pattern         = $this->compilePatternAsRegex( $this->URLPattern, $this->rules );
      $this->matcher_pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules, false );
      return $this;
    }
846822
protected function extendValidator($rule)
    {
        $method = studly_case($rule);
        $translation = $this->app['translator']->trans('image-validator::validation.' . $rule);
        $this->app['validator']->extend($rule, 'Cviebrock\ImageValidator\ImageValidator@validate' . $method,
            $translation);
        $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method);
    }
799885
public function rules(array $rules)
    {
        foreach ($rules as $ruleType => $params) {
            if (\is_array($params)) {
                foreach ($params as $innerParams) {
                    $innerParams = (array) $innerParams;
                    $this->rule($ruleType, ...$innerParams);
                }
            } else {
                $this->rule($ruleType, $params);
            }
        }

        return $this;
    }
313925
protected function parseValidationRule($rule)
    {
        $ruleArray = array();

        $explodedRule = explode(':', $rule, 2);
        $ruleArray['name'] = array_shift($explodedRule);

        if (empty($explodedRule) || !in_array(strtolower($ruleArray['name']), static::$multiParamRules)) {
            $ruleArray['parameters'] = $explodedRule;
        } else {
            $ruleArray['parameters'] = str_getcsv($explodedRule[0]);
        }

        return $ruleArray;
    }
144876
public function validationRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->validationRules;
        }

        $this->validationRules = $rules;

        return $this;
    }
267851
private function isRule($rule) {

		if(false === is_string($rule)) {
			return false;
		}

		$class = $this -> getRuleClass($rule);

		return true === class_exists($class);
	}
737538
public final function validate(array $data = null, array $rules = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if (empty($data)) {
			throw new ValidateException(['error' => 'data is empty']);
		}
		if ($rules) {
			$this->rules    = [];
			$this->rulesIdx = [];
			$this->ruleKeys = [];
			foreach ($rules as $field => $rule) {
				$this->addRule($field, $rule);
			}
		}

		return $this->validateNewData($data);
	}
220644
protected function validate( $attribute, $rule )
	{
		list( $rule, $parameters ) = $this->parseRule( $rule );

		if ( $rule == '' )
		{
			return;
		}

		// First we will get the correct keys for the given attribute in case the field is nested in
		// an array. Then we determine if the given rule accepts other field names as parameters.
		// If so, we will replace any asterisks found in the parameters with the correct keys.
		if ( ( $keys = $this->getExplicitKeys( $attribute ) ) && $this->dependsOnOtherFields( $rule ) )
		{
			$parameters = $this->replaceAsterisksInParameters( $parameters, $keys );
		}

		// We will get the value for the given attribute from the array of data and then
		// verify that the attribute is indeed validatable. Unless the rule implies
		// that the attribute is required, rules are not run for missing values.
		$value = $this->getValue( $attribute );

		$validatable = $this->isValidatable( $rule, $attribute, $value );

		$method = "validate{$rule}";

		if ( $validatable && !$this->$method( $attribute, $value, $parameters, $this ) )
		{
			$this->addFailure( $attribute, $rule, $parameters );
		}
	}