Validate by user function

@param string $paramName
@param mixed $data
@param array $params
@return mixed
@throws \Exception
344707
public static function validateByCallback($paramName, array $data,
                                              array $params)
    {
        if (isset($params['callback'])) {
            return $params['callback']($paramName, $data);
        } else {
            throw new \Exception('Callback parameter is required');
        }
    }
857061
public function validate($param)
    {
        /*
         * If we don't have a value to validate, check if it's required.
         * @link http://raml.org/spec.html#required
         */
        if (\in_array($param, [null, ''], true)) {
            if ($this->isRequired()) {
                throw new ValidationException($this->getKey() . ' is required', static::VAL_ISREQUIRED);
            }

            return;
        }

        switch ($this->getType()) {
            case static::TYPE_BOOLEAN:

                // Must be boolean
                if (!\is_bool($param)) {
                    throw new ValidationException($this->getKey() . ' is not boolean', static::VAL_NOTBOOLEAN);
                }

                break;
            case static::TYPE_DATE:

                // Must be a valid date
                if (!\DateTimeImmutable::createFromFormat('D, d M Y H:i:s T', $param)) {
                    throw new ValidationException($this->getKey() . ' is not a valid date', static::VAL_NOTDATE);
                }

                // no break

            case static::TYPE_STRING:

                // Must be a string
                if (!\is_string($param)) {
                    throw new ValidationException($this->getKey() . ' is not a string', static::VAL_NOTSTRING);
                }

                /**
                 * Check the length of a string.
                 *
                 * @link http://raml.org/spec.html#minlength
                 */
                $minLength = $this->getMinLength();
                if (!empty($minLength) && \strlen($param) < $minLength) {
                    throw new ValidationException(
                        $this->getKey() . ' must be at least ' . $minLength . ' characters long',
                        static::VAL_TOOSHORT
                    );
                }

                /**
                 * Check the length of a string.
                 *
                 * @link http://raml.org/spec.html#maxlength
                 */
                $maxLength = $this->getMaxLength();
                if (!empty($maxLength) && \strlen($param) > $maxLength) {
                    throw new ValidationException(
                        $this->getKey() . ' must be no more than ' . $maxLength . ' characters long',
                        static::VAL_TOOLONG
                    );
                }

                break;
            case static::TYPE_INTEGER:

                /*
                 * Integers must be of type integer.
                 *
                 * @link http://raml.org/spec.html#type
                 */
                if (!\is_int($param)) {
                    throw new ValidationException($this->getKey() . ' is not an integer', static::VAL_NOTINT);
                }
                // no break

            case static::TYPE_NUMBER:

                /*
                 * Number types must be numeric. ;)
                 *
                 * @link http://raml.org/spec.html#type
                 */
                if (!\is_numeric($param)) {
                    throw new ValidationException($this->getKey() . ' is not a number', static::VAL_NOTNUMBER);
                }

                /**
                 * Check the value constraints if specified.
                 *
                 * @link http://raml.org/spec.html#minimum
                 */
                $min = $this->getMinimum();
                if (!empty($min) && $param < $min) {
                    throw new ValidationException(
                        $this->getKey() . ' must be greater than or equal to ' . $min,
                        static::VAL_NUMLESSTHAN
                    );
                }

                /**
                 * Check the value constraints if specified.
                 *
                 * @link http://raml.org/spec.html#maximum
                 */
                $max = $this->getMaximum();
                if (!empty($max) && $param > $max) {
                    throw new ValidationException(
                        $this->getKey() . ' must be less than or equal to ' . $max,
                        static::VAL_GREATERTHAN
                    );
                }

                break;
            case static::TYPE_FILE:
                // File type cannot be reliably validated based on its type alone.

                break;
            case static::TYPE_TIME_ONLY:
            case static::TYPE_DATE_ONLY:
            case static::TYPE_DATETIME_ONLY:
            case static::TYPE_DATETIME:
                $typeObject = ApiDefinition::determineType(
                    $this->key,
                    [
                        'type' => $this->getType(),
                        'format' => $this->getFormat(),
                    ]
                );
                $typeObject->validate($param);
                if (!$typeObject->isValid()) {
                    throw new ValidationException($typeObject->getErrors()[0]);
                }

                break;
        }

        /**
         * Validate against the RAML specified pattern if it exists.
         *
         * @link http://raml.org/spec.html#pattern
         */
        $validationPattern = $this->getValidationPattern();
        if (!empty($validationPattern) &&
            \preg_match('|' . $validationPattern . '|', $param) !== 1
        ) {
            throw new ValidationException(
                $this->getKey() . ' does not match the specified pattern',
                static::VAL_PATTERNFAIL
            );
        }

        /*
         * If we have an enum (array), then it must be a specified value.
         *
         * NOTE: The RAML spec states that "enum" only applies to strings. However, it
         * could just as easily apply to integers or any other data type that an array
         * can hold in a YAML structure.
         *
         * @link http://raml.org/spec.html#enum
         */
        if (\is_array($enum = $this->getEnum()) && !\in_array($param, $enum, true)) {
            throw new ValidationException(
                $this->getKey() . ' must be one of the following: ' . \implode(', ', $enum),
                static::VAL_NOTENUMVALUE
            );
        }
    }
456435
public function setParams(array $params = array())
    {
        if (empty($params)) {
            throw new Exception('Unable to send exception. Invalid data provided.');
        }
        $this->description = isset($params['description']) ? $params['description'] : null;
        $this->url         = isset($params['url']) ? $params['url'] : null;
        $this->src         = isset($params['src']) ? $params['src'] : null;
        return $this;
    }
722951
private function createQueryError(string $paramName, string $errorTitle): ErrorInterface
    {
        $source = [ErrorInterface::SOURCE_PARAMETER => $paramName];
        $error  = new JsonApiError(null, null, null, null, null, $errorTitle, null, $source);

        return $error;
    }
1346548
public static function validateEquality($paramName, array $data,
                                            array $params = [])
    {
        $result = true;

        if (!isset($data[$paramName])) {
            throw new \Exception('Parameter is not set');
        }
        if (!isset($params['equalTo'])) {
            throw new \Exception('Parameter \'equalTo\' is required');
        }

        if ($data[$paramName] !== $data[$params['equalTo']]) {
            $result = false;
        }

        return $result;
    }
804319
protected function validateParams(array &$params, $rules = null, $clean = false)
	{

		if( ! is_null($rules) )
		{
			// init laravel validator
			$validator = $this->newValidator($params, $rules, $clean);
			$this->setValidator($validator);
		}
		$validator = $this->getValidator();

		$rules = $validator->getRules();
		

		if ($validator->fails())
		{
			// params did not pass validation rules
			
			// add errors to exception
			$this->getException()->addErrors($validator->errors()->toArray());

			return false;
		}
		else
		{
			// params passed validation rules
			return true;
		}
	}
507146
public function validate(array $constraints, $data, $prettyName = 'This value')
    {
        if (gettype($data) == 'array') {
            $this->validateSequentialArray($data, $prettyName);
        } else {
            $message = $constraints['message'] ?? '%s must be a sequential array';
            throw new DataValidationException(sprintf($message, $prettyName));
        }

        parent::validate($constraints, $data, $prettyName);
    }
1293991
private function validateLogin($data, $username)
    {
        if(!is_object($data)) {
            return false; 
        }

        if (isset($data->error)) {
            return false;
        }

        if (isset($data->samaccountname) && strtolower($data->samaccountname) == strtolower($username)) {
            return true;
        }

        return null;
    }
16992
public void assertOne(final String paramName,
            final ParameterList parameters) throws ValidationException {

        if (parameters.getParameters(paramName).size() != 1) {
            throw new ValidationException(ASSERT_ONE_MESSAGE, new Object[] {paramName});
        }
    }
1264921
protected function validate(array $data)
    {
        $validator = $this->validator->make(
            $data,
            [
                'username' => 'min:6|max:60',
                'password' => 'min:6|max:255',
                'email' => 'email|max:100'
            ]
        );

        if ($validator->fails()) {
            $message = sprintf(
                'Invalid user credentials. %s',
                implode(' ', $validator->errors()->all())
            );
            throw new UserException($message);
        }
    }
216935
public static function validate($data)
    {
        if (count(array_intersect_key(array_flip(static::$requiredParams), $data)) === count(static::$requiredParams)) {
            return true;
        }

        throw new InvalidArgumentException();
    }
297751
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            
            $params = $params['0'];
            if (empty($params['dropbox_access_token']) || empty($params['dropbox_app_secret'])) {
                return false;
            }
            
            $client = m62Dropbox::getRemoteClient($params['dropbox_access_token'], $params['dropbox_app_secret']);
            $adapter = new m62Dropbox($client);
            
            $filesystem = new Remote($adapter);
            if (! $filesystem->getAdapter()->listContents()) {
                return false;
            }
            
            return true;
        } catch (\Exception $e) {
            
            $this->setErrorMessage($e->getMessage());
            return false;
        }
    }
631900
private function validate_params( \WP_REST_Request $data, $params ) {
		$collect = array();
		foreach ( $params as $param ) {
			$value = sanitize_text_field( $data[ $param ] );
			if ( empty( $value ) ) {
				return rest_ensure_response(
					new \WP_Error(
						'themeisle_' . $param . '_invalid',
						sprintf( 'Invalid %', $param ),
						array(
							'status' => 403,
						)
					)
				);
			} else {
				$collect[ $param ] = $value;
			}
		}

		return $collect;
	}
767465
private function validateAndThrowOnError(string $paramName, $value, int $ruleIndex): void
    {
        BlockInterpreter::executeBlock(
            $value,
            $ruleIndex,
            $this->getValidationBlocks(),
            $this->getContext(),
            $this->getCaptures(),
            $this->getValidationErrors()
        );
        $this->checkValidationQueueErrors($paramName);
    }
575433
private function callMethod($methodName, $datas)
    {
        if (method_exists($this, $methodName)) {
            $call = [$this, $methodName];
        } elseif (isset($this->extends[$methodName])) {
            $call = $this->extends[$methodName];
        } else {
            throw new MethodNotExistsException(sprintf('%s method is not exists in Validation class', $methodName));
        }

        if ($methodName !== 'runRequired') {
            $return = call_user_func_array([$this, 'runRequired'], count($datas) === 4 ? array_slice($datas, 1, 4) : $datas);
        }

        call_user_func_array($call, $datas);

        return $return;
    }
1185287
public function getParameter($paramName) {
		if(isset($this->params[$paramName])) {
					return $this->params[$paramName];
		}
		return null;
	}
1194971
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            $params = $params['0'];
            if (empty($params['rcf_username']) || empty($params['rcf_api'])) {
                return false;
            }
            
            return m62Rcf::getRemoteClient($params, false);
        } catch (\Exception $e) {
            return false;
        }
    }