/** * Converts a value from its PHP representation to its database representation of this type. * * @param mixed $value The value to convert. * * @return string */ public function convertToDatabaseValue($value) { if (null === $value) { return null; } if ($value instanceof Uuid || Uuid::isValid($value)) { return (string) $value; } throw ConversionException::conversionFailed($value, self::NAME); }
/** * Converts a value from its PHP representation to its database representation of this type. * * @param mixed $value The value to convert. * * @return MongoBinData */ public function convertToDatabaseValue($value) { if (null === $value) { return null; } if ($value instanceof MongoBinData) { return new MongoBinData($value->bin, MongoBinData::UUID_RFC4122); } if (is_string($value) && Uuid::isValid($value)) { $value = Uuid::fromString($value); } if ($value instanceof Uuid) { return new MongoBinData($value->getBytes(), MongoBinData::UUID_RFC4122); } throw ConversionException::conversionFailed($value, self::NAME); }