validate
@param      $type
@param      $data
@param bool $mayBeNull
@param bool $mayBeEmpty
@param bool $exceptions
@return bool
432301
public static function validate($type, $data, $mayBeNull = false, $mayBeEmpty = false, $exceptions = true)
    {
        $validator = new Validator();
        return $validator->validate($type, $data, $mayBeNull, $mayBeEmpty, $exceptions);
    }
111961
protected function validate($data, $rules=false)
    {
        if(!$rules)
        {
            $modelName = $this->modelFullName;
            $rules = $modelName::$rules;
        }
        $validator = \Validator::make($data, $rules);
        if($validator->fails()) throw new ValidationException($validator);
        return true;
    }
429896
public function validateChecksum($data)
    {
        if (!isset($data['checksum']) || !$this->getEsiKey()) {
            return false;
        }

        $suppliedChecksum = $data['checksum'];
        unset($data['checksum']);
        return $suppliedChecksum === $this->getChecksum($data);
    }
964981
public static function assertValid(string $type) : void
    {
        if ( ! array_key_exists($type, self::MAP))
        {
            throw new Exception(
                "The entered type $type is not valid.\n"
                . "Valid types: "
                . implode(
                    "\n\t",
                    array_unique(array_flip(self::MAP))
                )
            );
        }
    }
666077
public static function validateRequest($type)
    {
        $hasValidParams = isset(
            $_POST['id'],
            $_POST['app'],
            $_POST['remote'],
            $_POST['request'],
            $_POST['complement'],
            $_POST['nonce'],
            $_POST['filter'],
            $_POST['sort'],
            $_SESSION['efc'],
            $_SERVER['HTTP_X_REQUESTED_WITH']
        );

        if (! $hasValidParams || ! self::sanitizeParams()) {
            return false;
        }

        if (self::$config['complement'] !== $type) {
            return false;
        }

        $isAjaxRequest = $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';

        $isValidNonce = self::$config['nonce'] === $_SESSION['efc'];

        if (! $isAjaxRequest || ! $isValidNonce) {
            return false;
        }

        return true;
    }
786162
protected function validateData($data): void
    {
        if ($data instanceof FormInterface) {
            $data = $data->getData();
        }

        if (!\is_object($data)) {
            throw new UnexpectedTypeException($data, 'object');
        }
    }
876083
private function validateDefaultTypes($type, $value): bool
    {
        switch ($type) {
            case 'string':
                return is_string($value);
            case 'boolean':
                return is_bool($value);
            case 'integer':
                return is_int($value);
            case 'number':
                return is_numeric($value);
            case 'object':
                return is_object($value);
            case 'array':
                return $this->validateArrayType($value);
            case 'scheme':
                return in_array($value, ['http', 'https', 'ws', 'wss'], true);
            default:
                throw new Exception('Invalid type "' . $type . '"');
        }
    }
1173962
protected function throwInvalidTypeException(string $property, array $types, bool $optional = false)
    {
        $str = "Expected '{{types}}' for {{optional}} property '{{property}}' in {{class}}, got '{{actualtype}}'";

        throw new InvalidTypeException(Str::format($str, [
            'types'     => trim(
                str_replace('optional', '', implode('|', array_values($types))), '|'
            ),
            'optional'  => $optional ? 'optional' : null,
            'property'  => $property,
            'class'     => get_class($this),
            'actualtype'=> gettype($this->{$property}),
        ]));
    }
1058193
public function validate($data) {
        $result = parent::validate($data);
        if ($result !== true) {
            return $result;
        }
        $runningmethod = get_config('antivirus_clamav', 'runningmethod');
        if ($runningmethod === 'unixsocket') {
            $socket = stream_socket_client('unix://' . $data, $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
            if (!$socket) {
                return get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
            } else {
                // Send PING query to ClamAV socket to check its running state.
                fwrite($socket, "nPING\n");
                $response = stream_get_line($socket, 4);
                fclose($socket);
                if ($response !== 'PONG') {
                    return get_string('errorclamavnoresponse', 'antivirus_clamav');
                }
            }
        }
        return true;
    }
1258273
function validation($data, $files) {
        global $USER;
        $errors = parent::validation($data, $files);
        $reason = null;

        // ignore submitted username
        if (!$user = authenticate_user_login($USER->username, $data['password'], true, $reason, false)) {
            $errors['password'] = get_string('invalidlogin');
            return $errors;
        }

        if ($data['newpassword1'] <> $data['newpassword2']) {
            $errors['newpassword1'] = get_string('passwordsdiffer');
            $errors['newpassword2'] = get_string('passwordsdiffer');
            return $errors;
        }

        if ($data['password'] == $data['newpassword1']){
            $errors['newpassword1'] = get_string('mustchangepassword');
            $errors['newpassword2'] = get_string('mustchangepassword');
            return $errors;
        }

        if (user_is_previously_used_password($USER->id, $data['newpassword1'])) {
            $errors['newpassword1'] = get_string('errorpasswordreused', 'core_auth');
            $errors['newpassword2'] = get_string('errorpasswordreused', 'core_auth');
        }

        $errmsg = '';//prevents eclipse warnings
        if (!check_password_policy($data['newpassword1'], $errmsg)) {
            $errors['newpassword1'] = $errmsg;
            $errors['newpassword2'] = $errmsg;
            return $errors;
        }

        return $errors;
    }
1194761
protected function isCorrectObject($data, $type)
    {
        if ($data instanceof $type) {
            echo get_class($data) . "\n";
            echo $type . "\n";
            return true;
        }
        return false;
    }
781577
protected function createResult(array &$data, $type = null) {
		if ($type === null) {
			$type = $this->getResultType();
		}

		if ($type & self::RESULT_ARRAY) {
			return $data;
		}

		if ($type & self::RESULT_OBJECT) {
			return (object) $data;
		}

		if ($type & self::RESULT_MODEL) {
			return $this->create($data);
		}

		throw new Exceptions\InvalidResultType('Nothing to do with the type #' . $type);
	}
904261
public function validation($data, $files) {
        global $USER;
        $errors = [];

        $validrequesttypes = [
            api::DATAREQUEST_TYPE_EXPORT,
            api::DATAREQUEST_TYPE_DELETE
        ];
        if (!in_array($data['type'], $validrequesttypes)) {
            $errors['type'] = get_string('errorinvalidrequesttype', 'tool_dataprivacy');
        }

        if (api::has_ongoing_request($data['userid'], $data['type'])) {
            $errors['type'] = get_string('errorrequestalreadyexists', 'tool_dataprivacy');
        }

        // Check if current user can create data deletion request.
        $userid = $data['userid'];
        if ($data['type'] == api::DATAREQUEST_TYPE_DELETE) {
            if ($userid == $USER->id) {
                if (!api::can_create_data_deletion_request_for_self()) {
                    $errors['type'] = get_string('errorcannotrequestdeleteforself', 'tool_dataprivacy');
                }
            } else if (!api::can_create_data_deletion_request_for_other()
                && !api::can_create_data_deletion_request_for_children($userid)) {
                $errors['type'] = get_string('errorcannotrequestdeleteforother', 'tool_dataprivacy');
            }
        }

        return $errors;
    }
217333
public function validate($data, $throwException = true)
    {
        if (empty($rules = $this->getRules())) {
            return true;
        } else {
            $validator = Validator::make($data, $rules, $this->validationMessages);

            if ($validator->fails()) {
                $this->errors($validator->errors()->getMessages());
                if ($throwException) {
                    $errorString = DataFormatter::validationErrorsToString($this->getErrors());
                    throw new BadRequestException('Invalid data supplied.' . $errorString, null, null, $this->getErrors());
                } else {
                    return false;
                }
            } else {
                return true;
            }
        }
    }
1163926
protected function isValid($type, $data)
    {
        $valid = Validation::i();

        switch ($type) {
            case 'location':
                return $valid->isLocation($data);
            case 'utc':
                return $valid->isUtc($data);
            case 'abbr':
                return $valid->isAbbr($data);
            default:
                break;
        }

        return parent::isValid($type, $data);
    }
1331881
public function validate(ValidationData $data)
    {
        foreach ($this->getValidatableClaims() as $claim) {
            if (!$claim->validate($data)) {
                return false;
            }
        }

        return true;
    }
1307800
function validateIntegerHTTPInput( $data, $contentObjectAttribute, $classAttribute )
    {
        $min = $classAttribute->attribute( self::MIN_VALUE_FIELD );
        $max = $classAttribute->attribute( self::MAX_VALUE_FIELD );
        $input_state = $classAttribute->attribute( self::INPUT_STATE_FIELD );

        switch( $input_state )
        {
            case self::NO_MIN_MAX_VALUE:
            {
                $this->IntegerValidator->setRange( false, false );
                $state = $this->IntegerValidator->validate( $data );
                if( $state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE )
                    $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                         'The input is not a valid integer.' ) );
                else
                    return $state;
            } break;
            case self::HAS_MIN_VALUE:
            {
                $this->IntegerValidator->setRange( $min, false );
                $state = $this->IntegerValidator->validate( $data );
                if( $state === eZInputValidator::STATE_ACCEPTED )
                    return eZInputValidator::STATE_ACCEPTED;
                else
                    $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                         'The number must be greater than %1' ),
                                                                 $min );
            } break;
            case self::HAS_MAX_VALUE:
            {
                $this->IntegerValidator->setRange( false, $max );
                $state = $this->IntegerValidator->validate( $data );
                if( $state===1 )
                    return eZInputValidator::STATE_ACCEPTED;
                else
                    $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                         'The number must be less than %1' ),
                                                                 $max );
            } break;
            case self::HAS_MIN_MAX_VALUE:
            {
                $this->IntegerValidator->setRange( $min, $max );
                $state = $this->IntegerValidator->validate( $data );
                if( $state===1 )
                    return eZInputValidator::STATE_ACCEPTED;
                else
                    $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                         'The number is not within the required range %1 - %2' ),
                                                                 $min, $max );
            } break;
        }

        return eZInputValidator::STATE_INVALID;

    }