Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prefer-stable": true,
"require": {
"php": "^7.0|^8.0",
"doctrine/dbal": ">=v2.5.0"
"doctrine/dbal": "^4.0"
},
"config": {
"sort-packages": true,
Expand Down
16 changes: 8 additions & 8 deletions src/DBAL/Types/BaseDateTimeMicroWithTz.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
use Doctrine\DBAL\Types\Type;
use OwlCorp\DoctrineMicrotime\DBAL\Platform\DateTimeFormatTrait;
Expand All @@ -15,24 +15,24 @@ abstract class BaseDateTimeMicroWithTz extends Type
{
use DateTimeFormatTrait;

const NAME = null;
public const string NAME = 'datetimetz_micro';

public function getName()
public function getName(): string
{
return static::NAME;
}

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if ($platform instanceof PostgreSqlPlatform || $platform instanceof OraclePlatform) {
if ($platform instanceof PostgreSQLPlatform || $platform instanceof OraclePlatform) {
return 'TIMESTAMP(6) WITH TIME ZONE';
}

if ($platform instanceof SQLServer2008Platform) {
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
return $platform->getDateTimeTypeDeclarationSQL($column);
}

throw new DBALException(
throw new NotSupported(
\sprintf(
'%s ("%s") type is not supported on "%s" platform',
$this->getName(),
Expand Down
26 changes: 13 additions & 13 deletions src/DBAL/Types/BaseDateTimeMicroWithoutTz.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\Type;
use OwlCorp\DoctrineMicrotime\DBAL\Platform\DateTimeFormatTrait;
Expand All @@ -17,32 +17,32 @@ abstract class BaseDateTimeMicroWithoutTz extends Type
{
use DateTimeFormatTrait;

const NAME = null;
public const string NAME = 'datetime_micro';

public function getName()
public function getName(): string
{
return static::NAME;
}

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if ($platform instanceof PostgreSqlPlatform) {
if ($platform instanceof PostgreSQLPlatform) {
return 'TIMESTAMP(6) WITHOUT TIME ZONE';
}

if ($platform instanceof MySqlPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration) . '(6)';
if ($platform instanceof MySQLPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($column) . '(6)';
}

if ($platform instanceof OraclePlatform) {
return 'TIMESTAMP(6)';
}

if ($platform instanceof SqlitePlatform || $platform instanceof SQLServerPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
if ($platform instanceof SQLitePlatform || $platform instanceof SQLServerPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($column);
}

throw new DBALException(
throw new NotSupported(
\sprintf(
'%s ("%s") type is not supported on "%s" platform',
$this->getName(),
Expand Down
26 changes: 13 additions & 13 deletions src/DBAL/Types/BaseTimeMicro.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\Type;
use OwlCorp\DoctrineMicrotime\DBAL\Platform\DateTimeFormatTrait;
Expand All @@ -17,32 +17,32 @@ abstract class BaseTimeMicro extends Type
{
use DateTimeFormatTrait;

const NAME = null;
public const string NAME = 'time_micro';

public function getName()
public function getName(): string
{
return static::NAME;
}

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if ($platform instanceof PostgreSqlPlatform) {
if ($platform instanceof PostgreSQLPlatform) {
return 'TIME(6) WITHOUT TIME ZONE';
}

if ($platform instanceof MySqlPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration) . '(6)';
if ($platform instanceof MySQLPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($column) . '(6)';
}

if ($platform instanceof OraclePlatform) {
return 'TIMESTAMP(6)'; //there's no way to save just time
}

if ($platform instanceof SqlitePlatform || $platform instanceof SQLServerPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
if ($platform instanceof SQLitePlatform || $platform instanceof SQLServerPlatform) {
return $platform->getDateTimeTypeDeclarationSQL($column);
}

throw new DBALException(
throw new NotSupported(
\sprintf(
'%s ("%s") type is not supported on "%s" platform',
$this->getName(),
Expand Down
32 changes: 16 additions & 16 deletions src/DBAL/Types/DateTimeImmutableMicroType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@
namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\InvalidFormat;

final class DateTimeImmutableMicroType extends BaseDateTimeMicroWithoutTz
{
const NAME = 'datetime_immutable_micro';
public const string NAME = 'datetime_immutable_micro';

public function convertToDatabaseValue($phpVal, AbstractPlatform $platform)
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($phpVal === null) {
return $phpVal;
if ($value === null) {
return $value;
}

if ($phpVal instanceof \DateTimeImmutable) {
return $phpVal->format($this->getDateTimeFormatString($platform));
if ($value instanceof \DateTimeImmutable) {
return $value->format($this->getDateTimeFormatString($platform));
}

throw ConversionException::conversionFailedFormat(
$phpVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$this->getDateTimeFormatString($platform)
);
}

public function convertToPHPValue($dbVal, AbstractPlatform $platform)
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($dbVal === null || $dbVal instanceof \DateTimeImmutable) {
return $dbVal;
if ($value === null || $value instanceof \DateTimeImmutable) {
return $value;
}

$phpVal = \DateTimeImmutable::createFromFormat($this->getDateTimeFormatString($platform), $dbVal);
$phpVal = \DateTimeImmutable::createFromFormat($this->getDateTimeFormatString($platform), $value);
if ($phpVal !== false) {
return $phpVal;
}

try {
return new \DateTimeImmutable($dbVal); //it is usually able to guess
return new \DateTimeImmutable($value); //it is usually able to guess
} catch (\Throwable $t) {
throw ConversionException::conversionFailedFormat(
$dbVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$platform->getDateTimeFormatString()
);
Expand Down
32 changes: 16 additions & 16 deletions src/DBAL/Types/DateTimeMicroType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@
namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\InvalidFormat;

final class DateTimeMicroType extends BaseDateTimeMicroWithoutTz
{
const NAME = 'datetime_micro';
public const string NAME = 'datetime_micro';

public function convertToDatabaseValue($phpVal, AbstractPlatform $platform)
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($phpVal === null) {
return $phpVal;
if ($value === null) {
return $value;
}

if ($phpVal instanceof \DateTimeInterface) {
return $phpVal->format($this->getDateTimeFormatString($platform));
if ($value instanceof \DateTimeInterface) {
return $value->format($this->getDateTimeFormatString($platform));
}

throw ConversionException::conversionFailedFormat(
$phpVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$this->getDateTimeFormatString($platform)
);
}

public function convertToPHPValue($dbVal, AbstractPlatform $platform)
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($dbVal === null || $dbVal instanceof \DateTimeInterface) {
return $dbVal;
if ($value === null || $value instanceof \DateTimeInterface) {
return $value;
}

$phpVal = \DateTime::createFromFormat($this->getDateTimeFormatString($platform), $dbVal);
$phpVal = \DateTime::createFromFormat($this->getDateTimeFormatString($platform), $value);
if ($phpVal !== false) {
return $phpVal;
}

try {
return new \DateTime($dbVal); //it is usually able to guess
return new \DateTime($value); //it is usually able to guess
} catch (\Throwable $t) {
throw ConversionException::conversionFailedFormat(
$dbVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$platform->getDateTimeFormatString()
);
Expand Down
32 changes: 16 additions & 16 deletions src/DBAL/Types/DateTimeTzImmutableMicroType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@
namespace OwlCorp\DoctrineMicrotime\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\InvalidFormat;

final class DateTimeTzImmutableMicroType extends BaseDateTimeMicroWithTz
{
const NAME = 'datetimetz_immutable_micro';
public const string NAME = 'datetimetz_immutable_micro';

public function convertToDatabaseValue($phpVal, AbstractPlatform $platform)
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($phpVal === null) {
return $phpVal;
if ($value === null) {
return $value;
}

if ($phpVal instanceof \DateTimeImmutable) {
return $phpVal->format($this->getDateTimeTzFormatString($platform));
if ($value instanceof \DateTimeImmutable) {
return $value->format($this->getDateTimeTzFormatString($platform));
}

throw ConversionException::conversionFailedFormat(
$phpVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$this->getDateTimeTzFormatString($platform)
);
}

public function convertToPHPValue($dbVal, AbstractPlatform $platform)
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
{
if ($dbVal === null || $dbVal instanceof \DateTimeImmutable) {
return $dbVal;
if ($value === null || $value instanceof \DateTimeImmutable) {
return $value;
}

$phpVal = \DateTimeImmutable::createFromFormat($this->getDateTimeTzFormatString($platform), $dbVal);
$phpVal = \DateTimeImmutable::createFromFormat($this->getDateTimeTzFormatString($platform), $value);
if ($phpVal !== false) {
return $phpVal;
}

try {
return new \DateTimeImmutable($dbVal); //it is usually able to guess
return new \DateTimeImmutable($value); //it is usually able to guess
} catch (\Throwable $t) {
throw ConversionException::conversionFailedFormat(
$dbVal,
throw InvalidFormat::new(
$value,
$this->getName(),
$platform->getDateTimeTzFormatString()
);
Expand Down
Loading