Выбор значения с применением правила
@param null|\boolive\core\values\Rule $rule
@param null $error
@return mixed
540574
function get($rule = null, &$error = null)
    {
        // Если не указано правило и значение уже отфильтровано, то повторно фильтровать не нужно
        if (!$rule && $this->_filtered) return $this->getValue();
        // Если правило не указано, то берём по умолчанию
        if (!$rule) $rule = $this->getRule();
        // Если правило определено
        if ($rule instanceof Rule){
            return Check::filter($this->getValue(), $rule, $error);
        }
        $error = new Error(['Нет правила'], 'NO_RULE');
        return null;
    }
505595
protected function addViolation($error, Constraint $constraint)
    {
        $this->context->buildViolation($constraint->message)
            ->setParameter('%error%', $error)
            ->addViolation()
        ;

        return true;
    }
1072673
public function update($rule)
    {
        $ruleId = "";

        if (is_array($rule)) {
            $ruleId = $rule["id"];
            unset($rule["id"]);
        }
        elseif (is_object($rule)) {
            $ruleId = $rule->id;
            unset($rule->id);
        }

        return $this->client->put("/validation-rules/" . rawurlencode($ruleId), $rule);
    }
1305595
public function validate($failOn = Validator\Rule::ERROR)
    {
        $this->warnings = [];
        $this->errors = [];

        foreach ($this->rules as $rule) {

            if ($rule instanceof Validator\Condition) {
                // Condition

                $condition = $rule;
                if ($condition->validate()) {
                    // Conditions rules

                    if (!$condition->getValidator()->validate($failOn)) {

                        $this->errors = array_merge(
                            $this->errors,
                            $rule->getValidator()->getErrors()
                        );
                    }
                    $this->warnings = array_merge(
                        $this->warnings,
                        $rule->getValidator()->getWarnings()
                    );
                }
            } else {
                // Rule

                if (!$rule->validate()) {

                    if ($rule->getSeverity() <= $failOn) {
                        $this->errors[] = $rule;
                    } else {
                        $this->warnings[] = $rule;
                    }
                }
            }
        }

        // Run nested validators - every entity may have its own validator
        foreach ($this->entity->getData() as $propertyName => $value) {

            if ($value instanceof Entity) {

                $validator = $value->getValidator();

                if (!$validator->validate($failOn)) {

                    foreach ($validator->getErrors() as $error) {

                        $rule = clone $error;
                        $rule->setPath(
                            array_merge([$propertyName], $rule->getPath())
                        );
                        $this->errors[] = $rule;
                    }
                }

                foreach ($validator->getWarnings() as $warning) {

                    $rule = clone $warning;
                    $rule->setPath(
                        array_merge([$propertyName], $rule->getPath())
                    );
                    $this->warnings[] = $rule;
                }
            }
        }

        return count($this->errors) === 0;
    }
293152
public function mapRule(PersistenceRule $rule): Rule
    {
        $ruleData = [
            'id' => $rule->id,
            'status' => $rule->status,
            'layout' => function () use ($rule): ?Layout {
                try {
                    // Layouts used by rule are always in published status
                    return $rule->layoutId !== null ? $this->layoutService->loadLayout($rule->layoutId) : null;
                } catch (NotFoundException $e) {
                    return null;
                }
            },
            'enabled' => $rule->enabled,
            'priority' => $rule->priority,
            'comment' => $rule->comment,
            'targets' => new LazyCollection(
                function () use ($rule): array {
                    return array_map(
                        function (PersistenceTarget $target): Target {
                            return $this->mapTarget($target);
                        },
                        $this->layoutResolverHandler->loadRuleTargets($rule)
                    );
                }
            ),
            'conditions' => new LazyCollection(
                function () use ($rule): array {
                    return array_map(
                        function (PersistenceCondition $condition): Condition {
                            return $this->mapCondition($condition);
                        },
                        $this->layoutResolverHandler->loadRuleConditions($rule)
                    );
                }
            ),
        ];

        return Rule::fromArray($ruleData);
    }
679424
protected function checkRuleCorrect($rule)
    {
        if (!isset($rule->value)) {
            // We will assume a missing value for the rule is to be interpreted as empty.
            $rule->value = null;
        }
        if (!isset($rule->id, $rule->field, $rule->type, $rule->input, $rule->operator)) {
            return false;
        }
        if (!isset($this->operators[$rule->operator])) {
            return false;
        }

        return true;
    }
510891
public function updateRule($rule) {
        $logger = $GLOBALS['logger'];
        $path    = 'rules/update';
        $request = $this->_remoteServer->put(
            $path,
            array('Content-Type'=>'application/json'),
            $rule
        );
        try {
            $response = $request->send();
            if ($response->getStatusCode() !== 200) {
                throw new \Exception('Unable to handle request');
            }
            $rawResponse = $response->getBody('true');
            return $rawResponse;
        } catch (\Exception $e) {
            throw $e; 
        }
        
    }
941958
protected function onInvalidEventAttributeValidate($key, $check = [], $rule = NULL)
    {
        $this->validate[] = $rule ?: $key;

        return $this->required()->onInvalidEventCustomValidity($key, $check);
    }
664076
public function validate($rule = null)
    {
        if (is_null($rule)) {
            throw $this->exception('Incorrect usage of field validation');
        }

        if (is_string($rule)) {
            // If string is passed, prefix with the field name
            $rule = $this->short_name.'|'.$rule;
        } elseif (is_array($rule)) {
            // if array is passed, prepend with the rule
            array_unshift($rule, $this->short_name);
            $rule = array($rule);
        } elseif (is_callable($rule)) {
            // callable or something else is passed. Wrap into array.
            $rule = array(array($this->short_name, $rule));
        }

        $this->form->validate($rule);

        return $this;
    }
626118
protected function getRuleArgument($rule)
    {
        $exploded = explode(':', $rule);

        return isset($exploded[1]) ?
            array('rule' => $exploded[0], 'argument' => $exploded[1]) : null;
    }
37643
public function getFilterForRule(Rule $rule)
    {
        $filterIdentifier = $rule->getFilter();

        if (class_exists($filterIdentifier)) {
            return new $filterIdentifier;
        }

        $error = "Unable to locate filter for: $filterIdentifier defined in " . get_class($rule);
        throw new \UnexpectedValueException($error);
    }
788141
protected function checkRule($rule)
    {
        $this->assertTrue(is_array($rule) || is_string($rule));

        $parts = is_array($rule) ? $rule : explode('|', $rule);

        $this->assertTrue(isset($parts[0]));

        if ($this->enforceRequiredOrNullable()) {
            $this->assertTrue($parts[0] === 'required' || $parts[0] === 'nullable');
        }

        foreach ($parts as $part) {
            $this->assertInternalType('string', $part);
        }
    }
133043
public static function getRule($ruleName) {

		if (isset(self::$rules[$ruleName])) {
			return self::$rules[$ruleName];
		}

		return false;

	}
687893
public function getFilterForRule(Rule $rule)
    {
        $filterIdentifier = $rule->getFilter();

        if ($this->container === null || !$this->container->has($filterIdentifier)) {
            return parent::getFilterForRule($rule);
        }

        return $this->container->get($filterIdentifier);
    }
187240
private function validateAgainstExpression( $field, $value, $rule, $message = null )
    {
        if (preg_match($this->expressions[ $rule ], $value)) {
            return true;
        }

        if (!$message) {
            $message = $this->error_messages[ $rule ];
        }

        static::$errors[ $field ] = $message;

        return false;
    }
1085497
protected function _rule($rule, $error_message = null) {
        if (!$this->field) {
            throw new \Exception('Not specified fieldname');
        }
        $this->rules[$this->field][$rule] = $rule;
        if ($error_message) {
            $this->message($rule, $error_message, $this->field);
        }

        return $this;
    }
1231513
public function parse($value, $rule) {
        $rs = $value;

        if (!is_bool($value)) {
            if (is_numeric($value)) {
                $rs = $value > 0 ? TRUE : FALSE;
            } else if (is_string($value)) {
                $rs = in_array(strtolower($value), array('ok', 'true', 'success', 'on', 'yes')) 
                    ? TRUE : FALSE;
            } else {
                $rs = $value ? TRUE : FALSE;
            }
        }

        return $rs;
    }