Validates the input and returns an array containing validated data.

@throws \mako\validator\ValidationException
@return array
164703
public function validate(): array
	{
		if($this->isInvalid())
		{
			throw new ValidationException($this->errors, 'Invalid input.');
		}

		$validated = [];

		foreach(array_keys($this->ruleSets) as $validatedKey)
		{
			if(Arr::has($this->input, $validatedKey))
			{
				Arr::set($validated, $validatedKey, Arr::get($this->input, $validatedKey));
			}
		}

		return $validated;
	}
797382
public function validation()
	{
		if( ! $this->_validation)
		{
			$this->_validation = \Validation::forge(\Str::random('alnum', 32));

			if (isset(static::$_rules) and count(static::$_rules))
			{
				foreach (static::$_rules as $field => $rules)
				{
					$label = (isset(static::$_labels) and array_key_exists($field, static::$_labels)) ? static::$_labels[$field] : $field;
					$this->_validation->add_field($field, $label, $rules);
				}
			}
		}

		return $this->_validation;
	}
239499
public function validate()
    {
        // If validation is disabled, skip this step
        if (!DataObject::config()->uninherited('validation_enabled')) {
            return ValidationResult::create();
        }

        $valid = parent::validate();
        $validator = static::password_validator();

        if (!$this->ID || $this->isChanged('Password')) {
            if ($this->Password && $validator) {
                $userValid = $validator->validate($this->Password, $this);
                $valid->combineAnd($userValid);
            }
        }

        return $valid;
    }
788017
public function getInvalidData()
    {
        return array_combine(
            array_keys($this->invalidAttribs),
            array_map(function ($ref) {
                return $ref['value'];
            }, array_values($this->invalidAttribs))
        );
    }
1289978
public function validate()
    {
        if (($_FILES) && (isset($_FILES[$this->name]['name']))) {
            $value = $_FILES[$this->name]['name'];
            $size  = $_FILES[$this->name]['size'];
        } else {
            $value = null;
            $size  = null;
        }
        // Check if the element is required
        if (($this->required) && empty($value)) {
            $this->errors[] = 'This field is required.';
        }
        // Check field validators
        if (count($this->validators) > 0) {
            foreach ($this->validators as $validator) {
                if ($validator instanceof \Pop\Validator\ValidatorInterface) {
                    $class =  get_class($validator);
                    if ((null !== $size) &&
                        (('Pop\Validator\LessThanEqual' == $class) || ('Pop\Validator\GreaterThanEqual' == $class) ||
                         ('Pop\Validator\LessThan' == $class) || ('Pop\Validator\GreaterThan' == $class))) {
                        if (!$validator->evaluate($size)) {
                            $this->errors[] = $validator->getMessage();
                        }
                    } else {
                        if (!$validator->evaluate($value)) {
                            $this->errors[] = $validator->getMessage();
                        }
                    }
                } else if (is_callable($validator)) {
                    $result = call_user_func_array($validator, [$value]);
                    if (null !== $result) {
                        $this->errors[] = $result;
                    }
                }
            }
        }
        return (count($this->errors) == 0);
    }
719404
public function validate()
	{
		foreach ($this->validators as $validate)
		{
			$definition = $this->klass->getStaticPropertyValue($validate);
			$this->$validate(wrap_strings_in_arrays($definition));
		}

		$model_reflection = Reflections::instance()->get($this->model);

		if ($model_reflection->hasMethod('validate') && $model_reflection->getMethod('validate')->isPublic())
			$this->model->validate();

		$this->record->clear_model();
		return $this->record;
	}
1191418
public function validate()
    {
        $result = array();
        if(empty($this->slug)) $this->slug = $this->title;
        $this->slug = \lib\MyFunctions::slug($this->slug);
        if (empty($this->slug)) {
            $result['slug'] = Validate::cantLeaveBlank(_('Slug'));
        } else {
            $slugExists = self::checkSlug($this->slug,$this->id);
            if ($slugExists) {
                $result['slug'] = _('Repeated slug');
            }
        }
        if (empty($this->title)) {
            $result['title'] = Validate::cantLeaveBlank(_('Title'));
        }
        if (empty($this->description)) {
            $result['description'] = Validate::cantLeaveBlank(_('Description'));
        }

        return $result;
    }
1013908
public function rules()
	{
		$data = array();
		foreach ($this->validators as $validate)
		{
			$attrs = $this->klass->getStaticPropertyValue($validate);

			foreach (wrap_strings_in_arrays($attrs) as $attr)
			{
				$field = $attr[0];

				if (!isset($data[$field]) || !is_array($data[$field]))
					$data[$field] = array();

				$attr['validator'] = $validate;
				unset($attr[0]);
				array_push($data[$field],$attr);
			}
		}
		return $data;
	}
967633
public function validate()
    {
        $valid = true;
        $message = null;
        $type = $this->Type;

        // Check if empty strings
        switch ($type) {
            case 'URL':
            case 'Email':
            case 'Phone':
                if ($this->{$type} == '') {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_EMPTY'.strtoupper($type),
                        'You must enter a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
            case 'File':
            case 'SiteTree':
                if ($type && empty($this->{$type.'ID'})) {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_OBJECT',
                        'Please select a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
        }
        // if its already failed don't bother checking the rest
        if ($valid) {
            switch ($type) {
                case 'URL':
                    $allowedFirst = ['#', '/'];
                    if (!in_array(substr($this->URL, 0, 1), $allowedFirst) && !filter_var($this->URL, FILTER_VALIDATE_URL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDURL',
                            'Please enter a valid URL.  Be sure to include http:// for an external URL. or begin your internal url/anchor with a "/" character'
                        );
                    }
                    break;
                case 'Email':
                    if (!filter_var($this->Email, FILTER_VALIDATE_EMAIL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDEMAIL',
                            'Please enter a valid Email address'
                        );
                    }
                    break;
                case 'Phone':
                    if (!preg_match("/^\+?[0-9a-zA-Z\-\s]*[\,\#]?[0-9\-\s]*$/", $this->Phone)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDPHONE',
                            'Please enter a valid Phone number'
                        );
                    }
                    break;
            }
        }

        $result = ValidationResult::create();
        if (!$valid) {
            $result->addError($message);
        }

        $this->extend('updateValidate', $result);

        return $result;
    }
789454
public function validate()
    {
        foreach($this->rules() as $key => $value) {
            $this->rules[$key] =  [$this->input($key), $value];
        }

        $validate = $this->validator->validate($this->rules);

        if ($validate->fails()) {
            if($this->isAjax()) {
                return $this->response->json(['errors' => $validate->errors()->all()], 403);
            }

            return $this->redirect->backWith('errors', $validate->errors()->all());
        }
    }
654834
public function validateValidItem()
    {
        if (!$this->value) {
            return;
        }

        // load allowed values in values_list
        // @todo Imants: Actually we don't need to load all values from Model in
        //       array, just to check couple of posted values.
        //       Probably we should do SELECT * FROM t WHERE id IN ($values) or
        //       something like that to limit array size and time spent on
        //       parsing all DB records in Model.
        $this->getValueList();

        $values = explode($this->separator, $this->value);
        foreach ($values as $v) {
            if (!isset($this->value_list[$v])) {
                $this->displayFieldError("Value $v is not one of the offered values");

                return $this->validate();
            }
        }
    }
550515
public function getValidAttribs()
    {
        return array_combine(
            array_keys($this->validAttribs),
            array_map(function ($ref) {
                return $ref['attrib'];
            }, array_values($this->validAttribs))
        );
    }
992092
public function getData()
    {
        $this->validate(
            'username',
            'password',
            'transactionId',
            'amount',
            'currency',
            'clientIp',
            'returnUrl',
            'cancelUrl',
            'notifyUrl',
            'clientMerchantId'
        );

        $document = new \DOMDocument('1.0', 'utf-8');
        $document->formatOutput = false;
        $document->createElement('soapenv:Header');

        $envelope = $document->appendChild(
            $document->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Envelope')
        );
        $envelope->setAttribute('xmlns:urn', 'urn:pscservice');

        $body = $envelope->appendChild(
            $document->createElement('soapenv:Body')
        );

        $disposition = $body->appendChild(
            $document->createElement('urn:createDisposition')
        );

        $disposition->appendChild(
            $document->createElement('urn:username', $this->getUsername())
        );

        $disposition->appendChild(
            $document->createElement('urn:password', $this->getPassword())
        );

        $disposition->appendChild(
            $document->createElement('urn:mtid', $this->getTransactionId())
        );

        $disposition->appendChild(
            $document->createElement('urn:subId', $this->getSubId())
        );

        $disposition->appendChild(
            $document->createElement('urn:amount', $this->getAmount())
        );

        $disposition->appendChild(
            $document->createElement('urn:currency', $this->getCurrency())
        );

        $disposition->appendChild(
            $document->createElement('urn:okUrl', rawurlencode($this->getReturnUrl()))
        );

        $disposition->appendChild(
            $document->createElement('urn:nokUrl', rawurlencode($this->getCancelUrl()))
        );

        $disposition->appendChild(
            $document->createElement('urn:pnUrl', rawurlencode($this->getNotifyUrl()))
        );

        $disposition->appendChild(
            $document->createElement('urn:shopId', $this->getShopId())
        );

        $disposition->appendChild(
            $document->createElement('urn:shopLabel', $this->getShopLabel())
        );

        $disposition->appendChild(
            $document->createElement('urn:merchantclientid', $this->getClientMerchantId())
        );

        if ($countryRestrictionValues = $this->getCountryRestrictions()) {
            $countryRestriction = $disposition->appendChild(
                $document->createElement('urn:dispositionRestrictions')
            );

            $countryRestriction->appendChild(
                $document->createElement('urn:key', 'COUNTRY')
            );

            $countryRestriction->appendChild(
                $document->createElement('urn:value', implode(',', $countryRestrictionValues))
            );
        }

        if ($minAgeRestrictionValue = $this->getMinAgeRestriction()) {
            $minAgeRestriction = $disposition->appendChild(
                $document->createElement('urn:dispositionRestrictions')
            );

            $minAgeRestriction->appendChild(
                $document->createElement('urn:key', 'MIN_AGE')
            );

            $minAgeRestriction->appendChild(
                $document->createElement('urn:value', $minAgeRestrictionValue)
            );
        }

        if ($minKycLevelRestrictionValue = $this->getMinKycLevelRestriction()) {
            $minKycLevelRestriction = $disposition->appendChild(
                $document->createElement('urn:dispositionRestrictions')
            );

            $minKycLevelRestriction->appendChild(
                $document->createElement('urn:key', 'MIN_KYC_LEVEL')
            );

            $minKycLevelRestriction->appendChild(
                $document->createElement('urn:value', $minKycLevelRestrictionValue)
            );
        }

        return $document->saveXML();
    }
821018
public function validate()
	{
		$this->errors->set();

		foreach ($this->rules as $key => $rule) {
			list ($fields, $type, $options) = $this->parseRule($rule);

			if (!$validator = $this->validators->$type) {
				$validator = $this->create($type);
				$this->validators->$type = $validator;
			}

			foreach ($fields as $key => $field) {
				$value = $this->dataSet->$field;

				if (!$validator->validate($value, $options)) {
					$this->addErrors($field, $validator->getErrors());
				}
			}
		}

		return !$this->hasErrors();
	}
953352
function validate() {
        $rules = [];
        foreach ($this->rules as $field => $_rules) {
            $this->rules[$field] = array_values($_rules);
        }

        $replacers = [];
        $id        = (int)Arr::get($this->data, $this->field_id);

        foreach ($this->rules as $field => $_rules) {
            foreach ($_rules as $rule) {
                if (is_string($rule)) {
                    $rules[$field][]           = str_replace('{id}', $id, $rule);
                    $replacer_name             = explode(":", $rule);
                    $replacer_rule             = array_shift($replacer_name);
                    $replacers[$replacer_rule] = [];
                }
                else {
                    $rules[$field][] = $rule;
                }

            }
        }
        if (count($replacers)) {
            /*foreach ($replacers as $rule => $vb) {
//                dd($replacers);
                \Validator::replacer(
                    $rule,
                    function ($message, $attribute, $rule, $parameters) {
                        $fields    = array_keys($this->data);
                        $replacers = array_map(
                            function ($value) {
                                return ':value=' . $value;
                            },
                            $fields
                        );
                        $replacers = array_merge(
                            $replacers,
                            array_map(
                                function ($value) {
                                    return ':label=' . $value;
                                },
                                $fields
                            )
                        );
                        return str_replace($replacers, $this->data + $this->labels, $message);
                    }
                );
            }*/
        }
        //        dd($this->messages);
        //        dd($this->labels);
        //        dump($this->labels);
        $this->validator = \Validator::make($this->data, $rules, $this->messages, $this->labels);
        foreach ($this->data as $k => $v) {
            $values['value__' . $k] = $v;
        }
        $this->validator->setValueNames($values);
        //        dd($this->validator);

        //        $this->validator->addReplacer()
        return !$this->validator->fails();
    }
466543
public function getValues() : array
    {
        $values = [];

        foreach ($this->inputs as $input) {
            $values[] = $input->getValue();
        }

        return $values;
    }
890492
public function validateRules()
    {
        $input = request()->all();
        $rules = [];
        $messages = [];

        if ($this->formRequest) {
            $this->formRequest = new $this->formRequest;
            $rules = $this->formRequest->rules();
            $messages = $this->formRequest->messages();
        }

        return Validator::make($input, $rules, $messages);
    }