Escapes given value.
@param mixed $value
@param string $type
@return mixed
@throws InvalidArgumentException
338546
public function escape($value, $type){
		switch($type){
			case Manager::BOOL:
				return $value ? 1 : 0;

			case Manager::TEXT:
			case Manager::BINARY:
				return "'" . sqlite_escape_string($value) . "'";

			case Manager::IDENTIFIER:
				return str_replace('[*]', '*', '[' . str_replace('.', '].[', $value) . ']');

			case Manager::DATETIME:
				return ($value instanceof DateTime) ? $value->format("'Y-m-d H:i:s'") : date("'Y-m-d H:i:s'", $value);

			default:
				throw new InvalidArgumentException('Unsupported data type.');
				break;
		}
	}
630664
public function escape($value)
    {
        if (is_numeric($value)) {
            return $value;
        }

        return is_string($value) ? htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false) : $value;
    }
464305
public static function encode($value)
    {
        $encoded = json_encode($value, JSON_UNESCAPED_UNICODE);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'Could not encode value into json. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $encoded;
    }
1062341
public function escapeSpecialChars($value)
    {
        $payPalEscape = oxNew(\OxidEsales\PayPalModule\Core\Escape::class);

        return $payPalEscape->escapeSpecialChars($value);
    }
21048
public function escape($value, $context = 'html')
    {
        if (is_numeric($value)) {
            return $value;
        }

        // If we deal with a scalar value, we can cache the result to increase
        // the performance when the same value is escaped multiple times (e.g. loops)
        if (is_scalar($value)) {
            if (!isset(self::$escaperCache[$context][$value])) {
                self::$escaperCache[$context][$value] = $this->getEscaper($context)($value);
            }

            return self::$escaperCache[$context][$value];
        }

        return $this->getEscaper($context)($value);
    }
364639
public static function decodeFromBase64(string $value, string $type = null)
    {
        return self::run(self::DECODER, \base64_decode($value), $type);
    }
1303692
private function validateType($type, $value, $name = '')
    {
        $valueType = gettype($value);
        
        $codeException = $this->checkType($type, $value);
        
        if(1 === $codeException)
        {
            throw new InvalidArgumentException(sprintf('%s argument only accepts %s. Input type was: %s', $name, $type, $valueType));
        }
        
        if(2 === $codeException)
        {
            throw new RuntimeException('The argument is a resource, not is a valid type');
        }
        
        if(3 === $codeException)
        {
            throw new RuntimeException(sprintf('Value not defined in validation for %s', $type));
        }
        
        return $value;
    }
170429
protected function setValue($value)
    {
        if (!is_string($value)) {
            throw InvalidTypeException::fromMessageAndPrototype("Value must be a string", static::prototype());
        }

        if(!mb_check_encoding($value, 'UTF-8')) {
            throw InvalidTypeException::fromMessageAndPrototype("Value must be a UTF-8 encoded", static::prototype());
        }

        $this->value = $value;
    }
121666
private function assertEscapeType($type)
    {
        if (! in_array($type, array_keys($this->escapeTypes), true)) {
            throw new Exception\InvalidEscaperException('Invalid escape type provided');
        }
    }
18480
public function processEscaped($value, $type = CorePDO::PARAM_STR)
    {
        if (!in_array($type, [CorePDO::PARAM_STR, CorePDO::PARAM_LOB])) {
            return $this->process($value, $type);
        }

        return $this->stringEscaped($value);
    }
955370
public static function invalidValue($type, $value)
    {
        if (is_object($value)) {
            $value = get_class($value);
        } elseif (is_bool($value) || is_null($value)) {
            $value = var_export($value, true);
        }

        return new self(sprintf('The type "%s" does not have a name for the value "%s".', $type, $value));
    }
862913
protected function findMail($type, $value)
    {
        $criterias = array($type => $value);

        $message = $this->getMailCatcherClient()->searchOne($criterias);

        if (null === $message) {
            throw new \InvalidArgumentException(sprintf('Unable to find a message with criterias "%s".', json_encode($criterias)));
        }

        return $message;
    }
825457
protected function formatValue($value, $type)
    {
        if (strtolower($type) == 'timestamp') {
            $value = '\'\'';
        } else if (strtolower($type) == 'datetime') {
            $value = '\'\'';
        } else if (strtolower($type) == 'date') {
            $value = '\'\'';
        } else if (strtolower($type) == 'time') {
            $value = '\'\'';
        } else if (stripos($type, 'int') !== false) {
            $value = intval($value);
        } else if (stripos($type, 'float') !== false) {
            $value = floatval($value);
        } else if (stripos($type, 'decimal') !== false) {
            $value = doubleval($value);
        } else {
            $value = '\'' . (string)$value . '\'';
        }

        return $value;
    }
1362174
public function checkValue(&$value)
    {
        if (is_string($value)) {
            $value = Placeholder::replaceStringsAndComments($value);
            $value = Placeholder::removeCommentPlaceholders($value, true);
            $value = Placeholder::replaceStringPlaceholders($value, true);
            $value = trim($value);

            if ($value !== '') {
                return true;
            } else {
                $this->setIsValid(false);
            }
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($value). "' for argument 'value' given."
            );
        }
    }
1002502
protected function escapeValue($value, $type = null){
		if(!$type){
			// NULL type
			if($value === null)
				return 'NULL';

			// Array of values w/o types
			elseif(is_array($value)){
				foreach($value as $k => $v)
					$value[$k] = $this->escapeValue($v);
				return $value;
			}

			// Value w/o type
			else{
				if($value instanceof DateTime){
					return $this->escapeValue($value, Manager::DATETIME);
				} elseif($value instanceof Literal){
					return $value->value;
				} elseif(is_bool($value)){
					return $this->stmt->getConnection()->getDriver()->escape($value, Manager::BOOL);
				} else{
					return is_numeric($value)
						? +$value
						: $this->stmt->getConnection()->getDriver()->escape($value, Manager::TEXT);
				}
			}
		}

		// Multiple values w/ types
		elseif(is_array($type)){
			foreach($value as $k => $v)
				$value[$k] = $this->escapeValue($v, $type[$k]);
			return $value;
		}

		// Single value w/ type
		elseif($type !== null){
			if($type === Manager::INT){
				return (int) $value;
			} elseif($type === Manager::FLOAT){
				return (float) $value;
			} elseif($type === Manager::SUBQUERY && $value instanceof Result){
				return "(\n\t" . implode("\n\t", explode("\n", $value)) . "\n)";
			} elseif($type === Manager::ARR){
				$arr = $value instanceof Traversable ? iterator_to_array($value) : (array) $value;
				return '(' . implode(', ', $this->escapeValue($arr)) . ')';
			} elseif($type === Manager::LITERAL){
				return $value instanceof Literal ? $value->value : $value;
			} else{
				return $this->stmt->getConnection()->getDriver()->escape($value, $type);
			}
		}
	}
103100
protected function toPhpType($value, $type)
    {
        switch ($type) {
            case 'int':
                return (int) $value;

            case 'string':
                return (string) $value;

            case 'datetime':
                return $value === '0000-00-00 00:00:00' ? '' : $value;

            case 'date':
                return $value === '0000-00-00' ? '' : $value;

            case 'bool':
                return (bool) $value;

            case 'array':
            case 'json':
                // Ignore default array value
                return is_array($value) ? $value : $this->cacheJsonDecode($value, true);

            case 'float':
                return (float) $value;

            default:
                throw new InvalidArgumentException('Unsupported cast type: ' . $type);
        }
    }
1276189
public function validateValueType($value)
    {
        if ($this->hasOption(Entity\Reflection\Property\Option\Primary::KEY)
            && (Entity\Reflection\Property\Option\Primary::isEmpty($value))
        ) {
            throw new Exception\InvalidArgumentException(
                "Primary value can not be empty string or null!",
                $value
            );
        }

        if ($value === null) {
            return;
        }

        // Enumeration
        if ($this->hasOption(Entity\Reflection\Property\Option\Enum::KEY)
            && !$this->getOption(Entity\Reflection\Property\Option\Enum::KEY)->isValid($value)
        ) {
            throw new Exception\InvalidArgumentException(
                "Value " . $value . " is not from defined entity enumeration "
                . "range on property " . $this->name . "!",
                $value
            );
        }

        // Scalar or array type
        if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {

            if (gettype($value) === $this->type) {
                return;
            }
            throw new Exception\InvalidArgumentException(
                "Expected " . $this->type . " but " . gettype($value)
                . " given on property " . $this->name . "!",
                $value
            );
        }

        // Object validation
        $givenType = gettype($value);
        if ($givenType === "object") {
            $givenType = get_class($value);
        }

        if ($this->type === self::TYPE_ENTITY) {
            // Entity

            $expectedEntityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if ($value instanceof $expectedEntityClass) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected entity " . $this->typeOption . " but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_COLLECTION) {
            // Collection

            $entityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if (!$value instanceof Entity\Collection) {

                throw new Exception\InvalidArgumentException(
                    "Expected entity collection but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            } elseif ($value->getEntityClass() !== $entityClass) {
                throw new Exception\InvalidArgumentException(
                    "Expected collection of entity " . $entityClass
                    . " but collection of entity " . $value->getEntityClass()
                    . " given on property " . $this->name . "!",
                    $value
                );
            } else {
                return;
            }
        } elseif ($this->type === self::TYPE_DATETIME) {
            // DateTime

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected DateTime but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_DATE) {
            // Date

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected date as DateTime object but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } else {
            // Unexpected

            throw new \Exception("Unsupported type " . $this->type . "!");
        }
    }