Get validated user input.

Check if input corresponds with fields under validation.

@param bool $clean Remove the input fields whose values are empty.

@return array
195558
public function getValidInput($clean = false)
    {
        $input = array_dot($this->all());
        $rules = array_keys($this->rules());

        $keys = collect($rules)->map(function (string $rule) use ($input) {
            // Transform each rule to a regex string while supporting
            // the wildcard (*) character to include sequential arrays too.
            $regex = '/^' . str_replace(['.', '*'], ['\.', '(.*)'], $rule) . '$/';

            // Match the regex string against our input fields
            return preg_grep($regex, array_keys($input));
        });

        // Match the input attributes against the existing rules
        $input = array_only($input, $keys->flatten()->toArray());

        // Reverse dot flattening to match original input
        $expanded = [];

        foreach ($input as $key => $value) {
            array_set($expanded, $key, $value);
        }

        if ($clean) {
            $expanded = $this->sanitizeInput($expanded);
        }

        return $expanded;
    }
246295
public function validate($removeRequired = false)
    {
        if ($removeRequired) {
            $this->removeRequired();
        }
        $content = $this->request->all();
        $messages = (method_exists($this, 'messages') && is_array($this->messages())) ? array_merge($this->messages, $this->messages()) : $this->messages;
        $this->validator = $this->app['validator']->make($content, $this->getRules(), $messages);
        /** get iterable keys and iterate */
        $mappings = $this->mappings();
        foreach ($mappings as $key => $value) {
            if (is_array($value) && class_exists($value['class']) && array_get($content, $key)) {
                $class = new $value['class']($this->app);
                $messages = (method_exists($class, 'messages') && is_array($class->messages())) ? array_merge($this->messages, $class->messages()) : $this->messages;
                $this->validator->iterate($this->request, $key, $class, $messages);
            }
        }

        if (method_exists($this, 'getSometimes')) {
            call_user_func_array([$this, 'getSometimes'], [$this->validator]);
        }

        if ($this->validator->fails()) {
            throw new ValidationException($this->validator->errors());
            
        }

        return $this->getDbValues($this->validator->getData(), $this->mappings());
    }
525859
public function getFields(bool $filter = true): array
    {
        $result = [];
        foreach ($this->fields as $name => $field) {
            $result[$name] = $this->getField($name, null, $filter);
        }

        return $result;
    }
404575
public function as_array( $clean = FALSE )
  {
    if($clean === TRUE)
    {
      $array = $this->_object;
    }
    else
    {
      $array = array();
      foreach($this->_object as $name => $value)
      {
        $array[$name] = isset($this->_object[$name]) ? $this->_object[$name] : NULL;
      }
      foreach($this->_aliases as $alias => $name)
      {
        if(isset($array[$name]))
        {
          $array[$alias] = $array[$name];
          unset($array[$name]);
        }
      }
    }

    return $array;
  }
405878
protected function clean_input( array $input ) {
		foreach ( $input as $key => $value ) {
			if ( is_array( $value ) ) {
				$input[ $key ] = $this->clean_input( $value );
			}

			if ( $value instanceof UploadedFile ) {
				unset( $input[ $key ] );
			}
		}

		return $input;
	}
372348
public function getBind($clear = true)
    {
        $bind = $this->bind;
        if ($clear) {
            $this->bind = [];
        }

        return $bind;
    }
399962
public function getErrors($clear = true)
    {
        $out = $this->_errors;
        if($clear) {
            $this->clearErrors();
        }
        return $out;
    }
176355
public function validate( $input )
    {
        $validatorClassNames = array();

        $validatorExceptions = array();

        foreach( $this->validators as $validator )
        {
            try {
                return $validator->validate( $input );
            } catch( phpillowValidationException $e ) {
                $validatorClassName                       = get_class( $validator );
                $validatorClassNames[]                    = $validatorClassName;
                $validatorExceptions[$validatorClassName] = $e;
            }
        }

        $exception = new phpillowValidationException(
            'Could not validate, as none of the given validators (%validators) validated the input.',
            array(
                'validators' => join( ',', $validatorClassNames )
            )
        );

        $exception->validatorExceptions = $validatorExceptions;

        throw $exception;
    }
21659
static function validateInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
    {
        $result = array( 'validated' => true, 'warnings' => array() );
        $validated =& $result['validated'];
        $warnings =& $result['warnings'];

        $http = eZHTTPTool::instance();

        $functionName = 'validateInput';
        $params = array( $http,
                         &$module,
                         &$class,
                         $object,
                         &$version,
                         $contentObjectAttributes,
                         $editVersion,
                         $editLanguage,
                         $fromLanguage,
                         $validationParameters );

        $validationResults = self::executeHandlerFunction( $functionName, $params );

        foreach( $validationResults as $validationResult )
        {
            $value = $validationResult['function']['value'];

            if ( $value['is_valid'] == false )
            {
                if ( $value['warnings'] )
                    $warnings = array_merge( $warnings, $value['warnings'] );

                $validated = false;
            }
        }

        return $result;
    }
871306
public function sanitize($input = false) {

        if($input) {

            if(Validate::isArray($input)) {

                return filter_var_array($input,FILTER_SANITIZE_STRING);
            } 
            if(Validate::isString($input)) {
                
                return filter_var($input, FILTER_SANITIZE_STRING);
            } 
        }

        return false;
    }
606887
public function getAll($remove = true)
    {
        $output = $this->messages;
        if (true === $remove) {
            $this->clear();
        }

        return $output;
    }
815247
public function getInputSpecification() : array
    {
        $spec = [
            'name'     => $this->getName(),
            'required' => $this->isRequired(),
        ];

        $filters = $this->getFilters();

        if ($this->node->hasAttribute('data-filters')) {
            foreach ($this->parseDataAttribute($this->node->getAttribute('data-filters')) as $name => $options) {
                $filters[] = [
                    'name'    => $name,
                    'options' => $options,
                ];
            }
        }

        if (! empty($filters)) {
            $spec['filters'] = $filters;
        }

        $validators = $this->getValidators();

        if ($this->node->hasAttribute('data-validators')) {
            foreach ($this->parseDataAttribute($this->node->getAttribute('data-validators')) as $name => $options) {
                $validators[] = [
                    'name'    => $name,
                    'options' => $options,
                ];
            }
        }

        if (! empty($validators)) {
            $spec['validators'] = $validators;
        }

        return $spec;
    }
1082995
public function getValidators()
    {
        $this->validators = $this->generateInputs();

        $translatedInputs = [];

        foreach ($this->validators as $key => $validator) {
            $translatedOperators = [];

            foreach ($validator['availableOperators'] as $availableOperators) {
                $translatedOperators[$availableOperators] = Operators::getI18n(
                    $this->translator,
                    $availableOperators
                );
            }

            $validator['availableOperators'] = $translatedOperators;

            $translatedInputs[$key] = $validator;
        }

        $validators = [
            'inputs'       => $translatedInputs,
            'setOperators' => $this->operators,
            'setValues'    => $this->values
        ];

        return $validators;
    }
529485
public function validateFields($input = null, \Closure $validation = null)
    {
        if (is_callable($input)) {
            $validation = $input;
            $input = null;
        }
        if (is_array($input)) {
            $this->input = array_merge($this->input, $input);
        }

        $rules = [];
        $fields = self::getFields();
        foreach ($fields as $field) {
            if (self::whetherValidateFiled($field)) {
                $ruleName = $this->input($field . '_rule');
                $rules[$field] = $this->getRealRuleByName($field, $ruleName);
            }
        }

        if ($validation) {
            return call_user_func_array($validation, [$this->input(), $rules]);
        }

        if (empty($this->input())) {
            return self::generateResult(false, 'empty_data');
        }

        $validator = Validator::make($this->input(), $rules);
        if ($validator->fails()) {
            $messages = $validator->errors();
            foreach ($fields as $field) {
                if ($messages->has($field)) {
                    $rule = $this->usedRule($field);
                    $msg = $messages->first($field);

                    return self::generateResult(false, $rule, $msg);
                }
            }
        }

        return self::generateResult(true, 'success');
    }
822505
public function check($form, $jsonInput = false)
    {
        $result = [];
        $errors = [];
        $inputs = [];

        if (is_array($form)) {
            $fields = $form;
        } else {
            $conditions = Cms::config('validation.'.$form);
            $fields = $conditions;
        }

        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $validationRules = $validationInputs = [];

        foreach ($fields as $key => $value) {
            if (isset($fields[$key])) {
                $inputs[$key] = $this->getInput($key, $jsonInput);
                $validationInputs[$key] = $this->getInput($key, $jsonInput);
                $validationRules[$key] = $fields[$key];
            }
        }

        $validation = Validator::make($validationInputs, $validationRules);

        if ($validation->fails()) {
            $errors = $validation->messages();
        }

        if (!$jsonInput) {
            $result['redirect'] = Redirect::back()->with('errors', $errors)->with('inputs', $this->inputsArray($jsonInput));
        }

        if (!empty($errors)) {
            $result['errors'] = $errors;
        } else {
            $result['errors'] = false;
        }

        $result['inputs'] = $this->inputsArray($jsonInput);

        return $result;
    }
1092373
public function fetchMessages($clear = true)
    {
        $messages = $this->messages;
        if ($clear) {
            $this->clear();
        }

        return $messages;
    }
603467
public function getInputFilterSpecification()
    {
        return array(
            'firstName' => array(
                'required'   => true,
                'filters'    => array(
                    array('name' => '\Zend\Filter\StringTrim'),
                ),
                'validators' => array(
                    new NotEmpty(),
                    new StringLength(array('max' => 50))
                ),
            ),
            'lastName'  => array(
                'required'   => true,
                'filters'    => array(
                    array('name' => 'Zend\Filter\StringTrim'),
                ),
                'validators' => array(
                    new NotEmpty(),
                    new StringLength(array('max' => 50))
                ),
            ),
            'email'     => array(
                'required'   => true,
                'filters'    => array(
                    array('name' => 'Zend\Filter\StringTrim'),
                ),
                'validators' => array(
                    new NotEmpty(),
                    new StringLength(array('max' => 100)),
                    new EmailAddress()
                )
            ),
            'image'     => array(
                'required'   => false,
                'filters'    => array(),
                'validators' => array(
                    new File\Exists(),
                    new File\Extension(array('extension' => array('jpg', 'png', 'jpeg', 'gif'))),
                ),
            ),
        );
    }