Formats input so it can be safely used in a query

@param mixed  $input Value to quote
@param string $type  Type of data (integer, bool, ident)

@return string Quoted/converted string for use in query
498759
public function quote($input, $type = null)
    {
        // handle int directly for better performance
        if ($type == 'integer' || $type == 'int') {
            return intval($input);
        }

        if (is_null($input)) {
            return 'NULL';
        }

        if ($input instanceof DateTime) {
            return $this->quote($input->format($this->options['datetime_format']));
        }

        if ($type == 'ident') {
            return $this->quote_identifier($input);
        }

        // create DB handle if not available
        if (!$this->dbh) {
            $this->db_connect('r');
        }

        if ($this->dbh) {
            $map = array(
                'bool'    => PDO::PARAM_BOOL,
                'integer' => PDO::PARAM_INT,
            );

            $type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;

            return strtr($this->dbh->quote($input, $type),
                // escape ? and `
                array('?' => '??', self::DEFAULT_QUOTE => self::DEFAULT_QUOTE.self::DEFAULT_QUOTE)
            );
        }

        return 'NULL';
    }
484661
public function quoteField(string $input): string
    {
        $input = $this->unquoteField($input);

        // nope.. quote all
        // if (ctype_lower($input)) {
        //     return $input;
        // }

        if ($this->isMysql()) {
            return '`'. str_replace('`', '``', $input) .'`';
        } elseif ($this->isPgsql()) {
            return '"'. str_replace('"', '""', $input) .'"';
        }
    }
253999
public static function to_type(&$value, string $type='', bool $flatten=false) {
		switch (\strtolower($type)) {
			case 'string':
				static::string($value, $flatten);
				break;
			case 'int':
			case 'integer':
				static::int($value, $flatten);
				break;
			case 'double':
			case 'float':
			case 'number':
				static::float($value, $flatten);
				break;
			case 'bool':
			case 'boolean':
				static::bool($value, $flatten);
				break;
			case 'array':
				static::array($value);
				break;
		}
	}
22078
public static function format($type)
    {
        switch ($type) {
            case self::TYPE_CREATED:
                return 'Created';

            case self::TYPE_STARTING:
                return 'Starting';

            case self::TYPE_RUNNING:
                return 'Running';

            case self::TYPE_ENDING:
                return 'Ending';

            case self::TYPE_FINISHED:
                return 'Finished';

            case self::TYPE_SUCCESS:
                return 'Success';

            case self::TYPE_FAILURE:
                return 'Failure';

            default:
                return 'Unknown';
        }
    }
247314
public static function clean($input, $type)
    {
        if (!empty($input)) {
            if (!empty($type)) {
                if ($type === 'secured') {
                    return stripslashes(trim(htmlentities($input, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
                } elseif ($type === 'root') {
                    return stripslashes(trim(htmlentities(htmlspecialchars(strip_tags($input), ENT_QUOTES | ENT_HTML5, 'UTF-8'), ENT_QUOTES | ENT_HTML5, 'UTF-8')));
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
423843
function quote($val,$type=\PDO::PARAM_STR) {
		return $this->engine=='odbc'?
			(is_string($val)?
				\Base::instance()->stringify(str_replace('\'','\'\'',$val)):
				$val):
			$this->pdo->quote($val,$type);
	}
823011
protected function sanitizeValue($input, Sanitize $sanitize = null)
    {
        if (!isset($sanitize)) {
            $sanitize = $this->sanitize ?: Sanitize::removeTags()->trim()->toType();
        }

        if (is_array($input)) {
            $rawRule = $sanitize->getRawRules();
            $rawRule = current($rawRule);
            if ($rawRule instanceof Attributes) {
                return $sanitize->sanitize($input);
            }
            return Sanitize::attributes($sanitize)->sanitize($input);
        }

        return $sanitize->sanitize($input);
    }
10575
public function getType($input)
    {
        // Make an array to loop through
        $inputs = explode('|', $input);

        foreach ($inputs as $index => $input) {
            $list = (bool) preg_match('/\[\]$/', $input);
            if ($list === true) {
                $input = substr($input, 0, -2);
            }

            // make the type case insensitive
            $type = strtolower(trim($input));

            // Check if we can convert the type to a known type
            if (array_key_exists($type, $this->phpTypeMapping) === true) {
                $type = $this->phpTypeMapping[$type];
            }

            // Check if it is a predefined type
            if (in_array($type, $this->phpTypes) === true) {
                $inputs[$index] = $type . ($list ? '[]' : '');
                continue;
            }

            // Reset the type. Maybe it is a class definition
            $type = $input;

            if ($this->isClassDefined($type) === true) {
                $inputs[$index] = $type . ($list ? '[]' : '');
                continue;
            }

            throw Exception\ClassFile::phpTypeDoesNotExists($type);
        }

        return implode('|', $inputs);
    }
745580
public static function escapeInput(string $input): string
    {
        $escaped_input = htmlspecialchars(stripslashes(trim($input)));
        return $escaped_input;
    }
849386
public function getAsString(string $type): ?string
    {
        $ret = $this->entry[$type];
        if (is_array($ret)) {
            $ret = implode('', $ret);
        }
        return $ret;
    }
1133626
public function interpolate($input)
    {
        $keys = array_keys($this->interpolation_vars);
        $values = array_values($this->interpolation_vars);
        return str_replace($keys, $values, $input);
    }
134425
public function input($type, $name, $value = '', $options = [])
    {
        if (!isset($options['id'])) {
            $options['id'] = $name;
        }

        if (!empty($value)) {
            $options['value'] = $value;
        }

        $options['type'] = $type;
        $options['name'] = $name;

        return '<input'.$this->attributes($options).'>';
    }
704808
public static function input($name, $type = INPUT_SERVER)
    {
        //====================================================================//
        // Standard Safe Reading
        $result = filter_input($type, $name);
        if (null !== $result) {
            return $result;
        }
        //====================================================================//
        // Fallback Reading
        if ((INPUT_SERVER === $type) && isset($_SERVER[$name])) {
            return $_SERVER[$name];
        }
        if ((INPUT_GET === $type) && isset($_GET[$name])) {
            return $_GET[$name];
        }

        return null;
    }
856383
public function quote($string, $type='string')
    {
        if ($type == 'string') {
            return "'" . str_replace("'", "''", $string) . "'";
        }

        if ($type != 'name') {
            throw new InvalidArgumentException("type has to be either string|name, not $type");
        }

        return '"' . str_replace('"', '""', $string) . '"';
    }
846350
public function format($key, $type)
    {
        if (is_file($key)) {
            $key = file_get_contents($key);
        }

        if (is_string($key) && strpos($key, '-----') === false) {
            $key = $this->convertKey($key, $type);
        }

        return $key;
    }
239096
public function quote($value, $type = DB::PARAM_AUTO) {
        if (is_array($value))
            return sprintf('(%s)', implode(', ', array_map(function($v) use($this, $type) {
                                return $this->quote($v, $type);
                            }, $value)));
        $type = ($type == DB::PARAM_AUTO) ? $this->quotedType($value) : $type;
        switch ($type) {
            case DB::PARAM_STR:
                $value = $this->escapeString($value);
                break;
            case DB::PARAM_DATE:
            case DB::PARAM_TIME:
            case DB::PARAM_DATETIME:
                switch ($type) {
                    case DB::PARAM_DATE:
                        $format = 'Y-m-d';
                        break;
                    case DB::PARAM_TIME:
                        $format = 'H:i:s';
                        break;
                    default:
                        $format = 'Y-m-d H:i:s';
                }
                if (interface_exists('\\DateTimeInterface') and $value instanceof \DateTimeInterface or $value instanceof \DateTime)
                    $value = $value->format($format);
                else {
                    $dt = date_create($value);
                    if ($dt === false)
                        $dt = new \DateTime;
                    if (is_int($value))
                        $dt->setTimestamp($value);
                    $value = $dt->format($format);
                }
                break;
            case DB::PARAM_INT:
                $value = intval($value);
                break;
            case DB::PARAM_BOOL:
                $value = $value ? 1 : 0;
                break;
            case DB::PARAM_FLOAT:
                $value = floatval($value);
                break;
            case DB::PARAM_NULL:
                $value = 'NULL';
                break;
            default:
                throw new \UnexpectedValueException('Invalid parameter value');
        }
        return ($type & DB::PARAM_STR) ? "'$value'" : $value;
    }
1006459
protected function normalizeColumn(string $input): string
    {
        if ($this->columnHasAlias($input)) {
            list($rawColumn, $rawAlias) = explode('AS', $input);
        } else {
            $rawColumn = $input;
            $rawAlias = '';
        }

        $column = $this->getQuotedName(trim($rawColumn));

        return empty($rawAlias) ?
            $column :
            $this->columnAs($column, $this->getQuotedName(trim($rawAlias)));
    }