Validate search sort by order.

@param string $data Sort by order value
@return string
178697
protected static function validateSortByOrder(string $data): string
    {
        $options = array_keys(Options::getSortByOrders());
        if (!in_array($data, $options)) {
            $data = Options::DEFAULT_SORT_BY_ORDER;
        }

        return $data;
    }
560673
public function checkString($data)
    {
    	$data = trim($data);
		$data = stripslashes($data);
		$data = htmlspecialchars($data);
		return $data;
    }
1186004
protected function validate($data)
    {
        $data = $this->validateSegment($data);
        if (! $data) {
            return $data;
        }

        $this->saveInternalEncoding();
        if (! $this->isValidHostLength($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid hostname, check its length');
        }

        if (! $this->isValidHostPattern($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid host label, check its content');
        }

        if (! $this->isValidHostLabels($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid host label counts, check its count');
        }

        $data = $this->sanitizeValue($data);
        $data = explode(
            $this->delimiter,
            $this->punycode->decode(implode($this->delimiter, $data))
        );
        $this->restoreInternalEncoding();

        return $data;
    }
981768
protected function validateMappedValues(array $data)
    {
        $errors = [];

        foreach (array_diff_key($this->properties, [ ':any_name:' => 1 ]) as $key => $property) {
            $result = $this->selectValue($property, $data);
            if ($result instanceof Ok) {
                $value = $result->unwrap();
                if ($value === null) {
                    continue;
                }
                $result = $property->validate($value);
            }
            if ($result instanceof Error) {
                $errors[$key] = $result->unwrap();
            }
        }

        return empty($errors) ? Ok::unit() : Error::unit($errors);
    }
216875
public function validate($data) {
    if ($data === NULL) throw $this->emptyException();
    if (!is_array($data)) throw $this->invalidArgument(1, $data, 'Array', __FUNCTION__);
    
    foreach ($this->languages as $lang) {
      if (!array_key_exists($lang, $data)) {
        throw $this->emptyException();
      }
      
      try {
        $data[$lang] = $this->wrappedRule->validate($data[$lang]);
      } catch (EmptyDataException $e) {
        throw $this->emptyException($e);
      }
    }
    
    return $data;
  }
1158351
private static function validateStore($data)
    {
        // custom messages for validation
        $validationMessagesTemplate = array(
          'required'=> "{{field}} can't be empty",
          'email'=>"{{field}} must be an email",
          'integer'=>"{{field}} must be a number",
        );
        $validationMessages = array();
        $validationRules = array();
        $validationValues= array();

        //setup title validation
        $isOneTitleFilled = false;
        foreach ($data['title'] as $title){
            if($title !== '') {
                $isOneTitleFilled = true;
            }
        }
        if (!$isOneTitleFilled) {
            foreach ($data['languages'] as $lang) {
                $validationMessages["title_" . $lang['slug'].".required"] = str_replace("{{field}}", "Title", $validationMessagesTemplate["required"]);
                $validationRules["title_" . $lang['slug']] = 'required';
                $validationValues["title_" . $lang['slug']] = $data['title'][$lang['slug']];
            }
        }

        // Custom fields validation
        foreach($data['formData'] as $formData){ // loop throw form data
            if ($formData['required']) { // check if input is required
                if(!$formData['translatable']) { // if input is not multilanguage
                    foreach ($data['languages'] as $lang){
                        // if it is not a file return required error
                        if($formData['type']['inputType'] != "image" && $formData['type']['inputType'] != "file") {
                            if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $lang['slug'].".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'required';
                                $validationValues[$formData['slug']. "_" . $lang['slug']] = $formData['value'];
                            }
                        }else{
                            if($formData['translatable']) {
                                $imageKey = $formData['slug']."_".$lang['slug'];
                            }else{
                                $imageKey = $formData['slug'];
                            }

                            if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $lang['slug'].".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'required';
                            }

                            if(!isset($data['files'][$imageKey])) {  // errors if images or files are not set and the language is status
                                if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $lang['slug']] = "";
                                }
                            }else{
                                $validationValues[$formData['slug']. "_" . $lang['slug']] = $data['files'][$imageKey];
                            }
                        }
                    }

                }else{ // if input is multilanguage
                    if ($formData['value']) {
                        foreach($formData['value'] as $langSlug => $value){ // loop throw the values for each language
                            if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                $validationMessages[$formData['slug'] . "_" . $langSlug.".required"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["required"]);
                                $validationRules[$formData['slug'] . "_" . $langSlug] = 'required';
                            }

                            //if is dropdown or checbox
                            if(is_array($value)) {
                                if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $langSlug] = $value;
                                }
                            }else {
                                if(isset($data['status']) && !is_integer($langSlug) && $data['status'][$langSlug] != 'draft') {
                                    $validationValues[$formData['slug']. "_" . $langSlug] = $value;
                                }
                            }
                        }
                    }
                }
            }

            /*
             * CUSTOM validations like email, number etc
             * */
            switch ($formData['type']['inputType']){
            case "email":
                foreach ($data['languages'] as $lang){
                    if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                        $validationMessages[$formData['slug'] . "_" . $lang['slug'] . ".email"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["email"]);

                        //set email rule
                        if(isset($validationRules[$formData['slug'] . "_" . $lang['slug']])) {
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] .= '|email';
                        }else{
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'email';
                        }
                    }
                }
                break;
            case "number":
                foreach ($data['languages'] as $lang){
                    if(isset($data['status']) && $data['status'][$lang['slug']] != 'draft') {
                        $validationMessages[$formData['slug'] . "_" . $lang['slug'] . ".integer"] = str_replace("{{field}}", $formData['name'], $validationMessagesTemplate["integer"]);

                        //set email rule
                        if(isset($validationRules[$formData['slug'] . "_" . $lang['slug']])) {
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] .= '|integer';
                        }else{
                            $validationRules[$formData['slug'] . "_" . $lang['slug']] = 'integer';
                        }
                    }
                }
                break;
            }
        }

        // Validate tags
        if($data['isFeaturedImageRequired']) {
            if(!isset($data['files']) || !isset($data['files']['featuredImage']) || (isset($data['files']['featuredImage']) && !count($data['files']['featuredImage']))) {
                $validationMessages["files_featuredImage.required"] = str_replace("{{field}}", "Featured Image ", $validationMessagesTemplate["required"]);
                $validationRules["files_featuredImage"] = 'required';
                $validationValues["featuredImage"] = "NONE";
            }
        }

        // Validatate categories
        if($data['isCategoryRequired']) {
            $validationMessages["categories.required"] = str_replace("{{field}}", "Categories", $validationMessagesTemplate["required"]);
            $validationRules["categories"] = 'required';
            $validationValues["categories"] = $data['selectedCategories'];
        }

        // Validate tags
        if($data['isTagRequired']) {
            foreach($data['selectedTags'] as $langKey => $tags){
                if(isset($data['status']) && $data['status'][$langKey] != 'draft') {
                    $validationMessages["tags_" . $langKey .".required"] = str_replace("{{field}}", "Tags", $validationMessagesTemplate["required"]);
                    $validationRules["tags_" . $langKey] = 'required';
                    $validationValues["tags_" . $langKey] = $data['selectedTags'][$langKey];
                }
            }
        }

        $validator = \Illuminate\Support\Facades\Validator::make($validationValues, $validationRules, $validationMessages);
        return $validator->messages();
    }
1073566
public function implement($data)
	{
		// input validation
		/*$validator = Validator::make($data->toArray(), [
			'position' => 'integer',
			'headline' => 'string',
			'label' => 'string',
			'type' => 'cetype|required',
			'html' => 'string',
			'form_input_type' => "input_type|required_if:type,input",
			'form_params' => 'json',
			'form_options' => 'json',
			#'cssid' => 'alpha_dash',
			#'cssclass' => 'alpha_dash'
		]);

		$validator->sometimes('form_name', 'alpha_dash|required', function ($input) {
			return (($this->type == "input") OR ($this->type == "textarea"));
		});

		$validator->sometimes('html_tag', 'string|required', function ($input) {
			return ($this->type == "wrapper");
		});

		// validation fail
		if($validator->fails())
		{
			\Log::error($validator->errors());
			return false;
		}*/

		// set element type
		$this->type = $data->type;

		// set attributes
		$this->html_attributes = (isset($data->html_attributes)) ? $data->html_attributes : null;

		if($this->type == "text")
		{
			$this->html = $data->html;
		}
		elseif($data->type == "input")
		{
			// set form input type
			$this->form_input_type = $data->form_input_type;

			if(isset($data->form_options))
				$this->form_options = $data->form_options;

			if(isset($data->label))
				$this->label = $data->label;
		}
		elseif($data->type == "wrapper")
		{
			$this->html_tag = $data->html_tag;
			$this->wrapper_type = $data->wrapper_type;
		}
		else
		{
			// error
			return false;
		}

		// successfully created
		return true;
	}
1306959
public function check($data = null)
    {
        $validator = $this->getValidator($data);

        if ($validator->isValid()) {
            return $this->suc();
        } else {
            return $this->err($validator->getFirstMessage());
        }
    }
1203002
public function match($data)
    {
        if (is_object($data)) {
            $data = get_class($data);
        }

        return in_array($data, (array)$this->getValue());
    }
304131
public function sort($data){

            $rule = call_user_func($this->rule);
            if($rule === "desc"){
                arsort($data, SORT_NATURAL);
            }else{
                asort($data, SORT_NATURAL);
            }

            return $data;

        }
786906
protected function formatData($data=null)
    {
        if (!is_null($data)) {
            if (is_scalar($data)) {
                $data = ['id' => $data];
            }
        } else {
            $data = (array) $data;
        }
        
        foreach ($data as $k => $v) {
            if ($v == "" || is_bool($v)) {
                $data[$k] = intval($v);
            } elseif (is_numeric($v)) {
                $data[$k] = (strpos($v, '.') !== false) ? floatval($v) : intval($v);
            }
        }
        
        $data && ksort($data);
        
        return $data;
    }
304731
private static function handleSort($query, $sort = null)
    {
        $replace = '';

        if ($sort !== null) {
            $sort ->validate(static::class);

            $tableAttribute = (
                $sort->table === null
                ? $sort->attribute
                : $sort->table . '"."' .$sort->attribute
            );

            $replace = "\n" . sprintf(
                'ORDER BY "%s" %s',
                $tableAttribute,
                ($sort->ascending ? 'ASC' : 'DESC')
            );
        }

        $query = str_replace(
            '{{sort}}',
            $replace,
            $query
        );

        return $query;
    }
992886
protected final function validateUpdateData(array $data = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if ($this->rules) {
			$newRules = [];
			foreach ($data as $key => $v) {
				if (isset($this->rules[ $key ])) {
					$newRules[ $key ] = $this->rules[ $key ];
				}
			}
			if ($newRules) {
				return $this->validateData($newRules, $data);
			}
		}

		return true;
	}
463283
public function applyOrderAndAliases(array $data)
    {
        if ($this->orderAndAliases === null) {
            return $data;
        }

        $processedData = [];

        foreach ($this->orderAndAliases as $key => $value) {
            if (\is_integer($key)) {
                $fieldName = $value;
                $fieldAlias = $value;
            } else {
                $fieldName = $key;
                $fieldAlias = $value;
            }

            $processedData[$fieldAlias] = null;
            if (array_key_exists($fieldName, $data)) {
                $processedData[$fieldAlias] = $data[$fieldName];
            }
        }

        return $processedData;
    }
384876
protected function getValuesForValidation($data = null)
  {
    $out = array();
    foreach ($this->fields as $field => $el) {
      $out[$field] = !is_null($data)
        ? isset($data[$field]) ? $data[$field] : false
        : $this->getValueFromRequest($field);
    }

    return $out;
  }
679244
public static function ksort($data)
    {
        if (static::isArray($data) ) {
            foreach ( $data as &$v ) {
                if (is_array($v)) {
                    $v = static::ksort($v);
                }
            }
        }

        ksort($data);

        return $data;
    }
3976
public function validEmail($data) {
		$data = array_shift($data);
		if (empty($data)) {
			return false;
		}

		if (is_array($data)) {
			return false;
		}

		$result = true;
		$emails = explode(CAKE_SETTINGS_APP_SMTP_EMAIL_DELIM, (string)$data);
		foreach ($emails as $email) {
			$email = trim($email);
			if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
				$result = false;
			}
		}

		return $result;
	}