| @@ 47-97 (lines=51) @@ | ||
| 44 | * @author Jonathan Wage <[email protected]> |
|
| 45 | * @author Roman Borschel <[email protected]> |
|
| 46 | */ |
|
| 47 | class DateTimeTzType extends Type |
|
| 48 | { |
|
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function getName() |
|
| 53 | { |
|
| 54 | return Type::DATETIMETZ; |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * {@inheritdoc} |
|
| 59 | */ |
|
| 60 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
| 61 | { |
|
| 62 | return $platform->getDateTimeTzTypeDeclarationSQL($fieldDeclaration); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * {@inheritdoc} |
|
| 67 | */ |
|
| 68 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
| 69 | { |
|
| 70 | if (null === $value) { |
|
| 71 | return $value; |
|
| 72 | } |
|
| 73 | ||
| 74 | if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 75 | return $value->format($platform->getDateTimeTzFormatString()); |
|
| 76 | } |
|
| 77 | ||
| 78 | throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); |
|
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * {@inheritdoc} |
|
| 83 | */ |
|
| 84 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
| 85 | { |
|
| 86 | if ($value === null || $value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 87 | return $value; |
|
| 88 | } |
|
| 89 | ||
| 90 | $val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value); |
|
| 91 | if ( ! $val) { |
|
| 92 | throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString()); |
|
| 93 | } |
|
| 94 | ||
| 95 | return $val; |
|
| 96 | } |
|
| 97 | } |
|
| 98 | ||
| @@ 29-79 (lines=51) @@ | ||
| 26 | * |
|
| 27 | * @since 2.0 |
|
| 28 | */ |
|
| 29 | class DateType extends Type |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * {@inheritdoc} |
|
| 33 | */ |
|
| 34 | public function getName() |
|
| 35 | { |
|
| 36 | return Type::DATE; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * {@inheritdoc} |
|
| 41 | */ |
|
| 42 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
| 43 | { |
|
| 44 | return $platform->getDateTypeDeclarationSQL($fieldDeclaration); |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
| 51 | { |
|
| 52 | if (null === $value) { |
|
| 53 | return $value; |
|
| 54 | } |
|
| 55 | ||
| 56 | if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 57 | return $value->format($platform->getDateFormatString()); |
|
| 58 | } |
|
| 59 | ||
| 60 | throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * {@inheritdoc} |
|
| 65 | */ |
|
| 66 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
| 67 | { |
|
| 68 | if ($value === null || $value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 69 | return $value; |
|
| 70 | } |
|
| 71 | ||
| 72 | $val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value); |
|
| 73 | if ( ! $val) { |
|
| 74 | throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); |
|
| 75 | } |
|
| 76 | ||
| 77 | return $val; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 29-79 (lines=51) @@ | ||
| 26 | * |
|
| 27 | * @since 2.0 |
|
| 28 | */ |
|
| 29 | class TimeType extends Type |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * {@inheritdoc} |
|
| 33 | */ |
|
| 34 | public function getName() |
|
| 35 | { |
|
| 36 | return Type::TIME; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * {@inheritdoc} |
|
| 41 | */ |
|
| 42 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
| 43 | { |
|
| 44 | return $platform->getTimeTypeDeclarationSQL($fieldDeclaration); |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
| 51 | { |
|
| 52 | if (null === $value) { |
|
| 53 | return $value; |
|
| 54 | } |
|
| 55 | ||
| 56 | if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 57 | return $value->format($platform->getTimeFormatString()); |
|
| 58 | } |
|
| 59 | ||
| 60 | throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * {@inheritdoc} |
|
| 65 | */ |
|
| 66 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
| 67 | { |
|
| 68 | if ($value === null || $value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
| 69 | return $value; |
|
| 70 | } |
|
| 71 | ||
| 72 | $val = \DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value); |
|
| 73 | if ( ! $val) { |
|
| 74 | throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString()); |
|
| 75 | } |
|
| 76 | ||
| 77 | return $val; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||