Sanitize recursively a value

@param mixed $value

@return mixed
513520
public function sanitize($value)
    {
        if ($value instanceof Traversable) {
            return $this->sanitize(iterator_to_array($value));
        } elseif (is_array($value)) {
            return array_map([$this, 'sanitize'], $value);
        } elseif (is_object($value)) {
            return $this->sanitizeObject($value);
        } elseif (is_resource($value)) {
            return get_resource_type($value);
        }

        return $value;
    }
1144840
protected function _sanitize($value)
    {
        $value = trim($value);

        $parts  = explode('-', $value, 2);
        if (2 != count($parts)) {
            return null;
        }

        $parts[0]   = substr(preg_replace('/[^a-z]*/', '', $parts[0]), 0, 2);
        $parts[1]   = substr(preg_replace('/[^A-Z]*/', '', $parts[1]), 0, 2);
        $result = implode('-', $parts);

        // just making sure :-)
        if ($this->_validate($result)) {
            return $result;
        }

        return null;
    }
770743
public static function sanitize_recursive( $values, $sanitizer ) {
		if ( ! is_array( $values ) ) {
			return is_scalar( $values ) ? $sanitizer( $values ) : $values;
		}

		foreach ( $values as $key => $value ) {
			if ( is_array( $value ) ) {
				$values[ $key ] = static::sanitize_recursive( $value, $sanitizer );
			} else {
				$values[ $key ] = is_scalar( $value ) ? $sanitizer( $value ) : $value;
			}
		}

		return $values;
	}
1084298
protected function _sanitize($value)
    {
        //Tidy is not installed, return the input
        if ($tidy = $this->getTidy($value)) {
            if ($tidy->cleanRepair()) {
                $value = (string) $tidy;
            }
        }

        return $value;
    }
1321518
public function sanitize($value)
    {
        if(!$value instanceof ObjectConfigJson)
        {
            if(is_string($value)) {
                $value = $this->getObject('object.config.factory')->fromString('json', $value);
            } else {
                $value = $this->getObject('object.config.factory')->createFormat('json', $value);
            }
        }

        return $value;
    }
214262
protected function preSerialization(array $value)
    {
        /** @var \NilPortugues\Api\Mapping\Mapping $mapping */
        foreach ($this->mappings as $class => $mapping) {
            RecursiveFilterHelper::deletePropertiesNotInFilter($this->mappings, $value, $class);
            RecursiveDeleteHelper::deleteProperties($this->mappings, $value, $class);
            $this->buildValidPropertyAlias($mapping);
            RecursiveRenamerHelper::renameKeyValue($this->mappings, $value, $class);
        }

        return $value;
    }
715382
protected function sanitizeValueFor($key, $value)
    {
        foreach ($this->rules[$key] as $rule) {
            $value = call_user_func_array(
                $this->getCallable($rule[0], $key),
                $this->buildArguments($value, isset($rule[1]) ? $rule[1] : null)
            );
        }

        return $value;
    }
879219
protected function _sanitize($value)
    {
        //strip php tags
        $value = preg_replace('/<\\?.*(\\?>|$)/Us', '', $value);
        $value = parent::_sanitize($value);

        return $value;
    }
339158
public static function cleanValue($value)
    {
        if (is_array($value)) {
            $new_value = [];

            foreach ($value as $k => $v) {
                $new_value[$k] = self::cleanValue($v);
            }

            return $new_value;
        }

        return stripslashes($value);
    }
1016607
public static function clean_vars($value){
        if(is_array($value)){
            foreach($value as $key => $val) {
                $value[$key] = self::clean_vars($val);
            }
        }
        else{
            $value= self::filter_simple_xss($value);
        }
        return $value;
    }
575611
public function clean($value)
  {
    if ($value==='' || $value===null || $value===false)
    {
      return null;
    }

    $tmp = PruneWhitespaceCleaner::get()->clean($value);
    if ($tmp==='' || $tmp===null)
    {
      return null;
    }

    return mb_substr($tmp, 0, $this->maxLength);
  }
345996
public static function SanitizeUTF8($value)
    {
        if (self::getIsIconvEnabled()) {
            $value = @iconv('UTF-8', 'UTF-8', $value);
            return $value;
        }

        if (self::getIsMbstringEnabled()) {
            $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
            return $value;
        }

        // else, no conversion
        return $value;
    }
1305698
public function wrapSanitizer($value)
    {
        // Its a raw query, just cast as string, object has __toString()
        if ($value instanceof Raw) {
            return (string)$value;
        }

        if ($value instanceof \Closure) {
            return $value;
        }

        // Separate our table and fields which are joined with a ".", like my_table.id
        $valueArr = explode('.', $value, 2);

        foreach ($valueArr as $key => $subValue) {
            // Don't wrap if we have *, which is not a usual field
            $valueArr[$key] = trim($subValue) === '*' ? $subValue : static::SANITIZER . $subValue . static::SANITIZER;
        }

        // Join these back with "." and return
        return implode('.', $valueArr);
    }
262761
public function sanitize($value)
    {
        if(!$value instanceof KObjectConfigJson)
        {
            if(is_string($value)) {
                $value = $this->getObject('object.config.factory')->fromString('json', $value);
            } else {
                $value = $this->getObject('object.config.factory')->createFormat('json', $value);
            }
        }

        return $value;
    }
503306
public function sanitize($value)
    {
        $value = (int) filter_var($value, FILTER_SANITIZE_NUMBER_INT);

        if(isset($this->max) && $value > (int) $this->max) {
            $value = (int) $this->max;
        }

        if(isset($this->min) && $value < (int) $this->min) {
            $value = (int) $this->min;
        }

        return $value;
    }
293228
public function sanitize($value)
    {
        $value = (string) $value;

        if (!empty($value)) {
            $value = JComponentHelper::filterText($value);
        }

        return $value;
    }
254385
protected function sanitizeToArrayValue($value)
    {
        if ($value instanceof Message) {
            return (new self($value))->toArray();
        }

        if ($value instanceof RepeatedField) {
            $values = [];
            foreach ($value as $k => $v) {
                $values[] = $this->sanitizeToArrayValue($v);
            }

            return $values;
        }

        if ($value instanceof self) {
            return $value->toArray();
        }

        return $value;
    }