Convert a PHP value to its SQL representation.

@param  mixed      $value     - PHP representation of a property value
@param  IConnector $connector - the used database connector

@return string - database representation
160135
public function convertToDBValue($value, IConnector $connector) {
        if ($value === null) {
            $value = 'null';
        }
        else {
            $type = $this->mapping['type'];
            switch ($type) {
                case 'bool'   :
                case 'boolean': $value = $connector->escapeLiteral((bool) $value); break;

                case 'int'    :
                case 'integer': $value = (string)(int) $value; break;

                case 'real'   :
                case 'float'  :
                case 'double' : $value = (string)(float) $value; break;

                case 'string' : $value = $connector->escapeLiteral((string) $value); break;

                default:
                    if (is_class($type)) {
                        $value = (new $type())->convertToDBValue($value, $this, $connector);
                        break;
                    }
                    throw new RuntimeException('Unsupported type "'.$type.'" for database mapping of '.$this->entityMapping->getClassName().'::'.$this->getName());
            }
        }
        return $value;
    }
1343103
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (empty($value)) {
            return null;
        }

        if (
            $value instanceof UuidInterface
            || (
                (is_string($value) || method_exists($value, '__toString'))
                && Uuid::isValid((string) $value)
            )
        ) {
            return (string) $value;
        }

        throw ConversionException::conversionFailed($value, static::NAME);
    }
1302011
public static function convertToDb($value)
    {
        $dbValue = null;

        if (is_array($value)) {
            $dbValue = (object) $value;
        } elseif ($value instanceof \ArrayObject) {
            $dbValue = (object) $value->getArrayCopy();
        } elseif (is_object($value)) {
            $dbValue = (object) get_object_vars($value);
        }

        if (!is_null($dbValue)) {
            $dbValue = (object) self::processDynamicParts($dbValue);
        }

        return $dbValue;
    }
744099
public function toPHP($value, Driver $driver)
    {
        if ($value === null) {
            return null;
        }
        if (is_string($value)
            && $driver instanceof Sqlserver
            && version_compare(PHP_VERSION, '7.0', '<')
        ) {
            $value = pack('H*', $value);
        }
        if (is_string($value)) {
            return fopen('data:text/plain;base64,' . base64_encode($value), 'rb');
        }
        if (is_resource($value)) {
            return $value;
        }
        throw new Exception(sprintf('Unable to convert %s into binary.', gettype($value)));
    }
219881
final public static function resolveValue($value, AbstractPlatform $platform)
    {
        if ($value instanceof DomainId) {
            $class = \get_class($value);
            $type = Type::INTEGER;

            foreach (self::$mapping as $mapping) {
                if ($class === $mapping['class']) {
                    $type = $mapping['data_type'] ?? $type;
                    break;
                }
            }

            return self::getType($type)->convertToPHPValue($value->isEmpty() ? null : $value->toString(), $platform);
        }

        return $value;
    }
492251
public function toDatabase($value, Driver $driver)
    {
        if ($value === null || is_string($value)) {
            return $value;
        }

        return serialize($value);
    }
1365055
protected function serializeType($value, $type)
    {
        return $this->connection->convertToDatabaseValue(
            $value,
            TypeMapper::getDoctrineTypeByType($type)
        );
    }
41562
private function quoteValue($value)
    {
        if (is_numeric($value)) {
            return $value;
        }

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

        return $this->getConnection()->quote($value);
    }
1029113
public function quote($value)
    {
        $PdoConnection = $this->getPdoConnection();
        if ($value === true) {
            return 1;
        }
        if ($value === false) {
            return 0;
        }
        // If a PDO database connection is set, use it to quote the value using
        // the underlying database. Otherwise, quote it manually.
        if ($PdoConnection) {
            return $PdoConnection->quote($value);
        } elseif (is_null($value)) {
            return "NULL";
        } else {
            return "'" . addslashes($value) . "'";
        }
    }
1113923
public function getSqlType($value)
    {
        if ('boolean' === gettype($value)) {
            return $this->connection->getDatabasePlatform()->convertBooleans($value);
        } elseif (null === $value || 'null' === $value) {
            return 'NULL';
        }

        return $this->connection->quote($value);
    }
1179649
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (!$value) {
            return null;
        }

        if ($platform instanceof MySqlPlatform) {
            $format = "POINT(%F %F)";
        } else {
            $format = "(%F, %F)";
        }

        return sprintf($format, $value->getLatitude(), $value->getLongitude());
    }
1287130
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (empty($value)) {
            return null;
        }

        if ($value instanceof Money) {
            return (string) $value->getCurrency().' '.$value->getAmount();
        }

        throw ConversionException::conversionFailed($value, self::NAME);
    }
1298191
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (null === $value || '' === $value) {
            return $value;
        }

        if ( ! $value instanceof Email) {
            $type = is_object($value) ? get_class($value) : gettype($value);
            throw new \InvalidArgumentException(sprintf('You have to pass an object of kind \SerendipityHQ\Component\ValueObjects\Email\Email to use the Doctrine type EmailType. "%s" passed instead.', $type));
        }

        // Validate the $value as a valid email
        $validator = new EmailValidator();

        if ( ! $validator->isValid($value, new RFCValidation())) {
            throw new \InvalidArgumentException(sprintf('An email field accepts only valid email addresses. The value "%s" is not a valid email.', $value));
        }

        // The value is automatically transformed into a string thans to the __toString() method
        return $value;
    }
360741
function prepValueForDB($value) {
		if(!$this->nullifyEmpty && $value === '') {
			return DB::getConn()->prepStringForDB($value);
		} else {
			return parent::prepValueForDB($value);
		}
	}
601864
public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if (null === $value || $value instanceof \DateTime) {
            return $value;
        }

        $converted = \DateTime::createFromFormat(
            $platform->getDateTimeFormatString(),
            $value,
            $this->getDateTimezone()
        );

        if (! $converted) {
            throw ConversionException::conversionFailedFormat(
                $value,
                $this->getName(),
                $platform->getDateTimeFormatString()
            );
        }
        return $converted;
    }
636624
public function toDatabase($value, Driver $driver)
    {
        if ($value === null || $value === '') {
            return null;
        }

        $this->checkNumeric($value);

        return (int)$value;
    }
1285270
public static function convertFromSQLHex($value)
    {
        $matches = array();
        if (preg_match_all('/(?:(?:\A|[^\d])0x[a-f\d]{3,}[a-f\d]*)+/im', $value, $matches)) {
            foreach ($matches[0] as $match) {
                $converted = '';
                foreach (str_split($match, 2) as $hex_index) {
                    if (preg_match('/[a-f\d]{2,3}/i', $hex_index)) {
                        $converted .= chr(hexdec($hex_index));
                    }
                }
                $value = str_replace($match, $converted, $value);
            }
        }
        // take care of hex encoded ctrl chars
        $value = preg_replace('/0x\d+/m', ' 1 ', $value);

        return $value;
    }