-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Christian Kolb <[email protected]>
- Loading branch information
1 parent
d9f1a50
commit 0df267f
Showing
49 changed files
with
2,098 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimePrecision\Doctrine; | ||
|
||
use DigitalCraftsman\DateTimePrecision\Weekday; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\StringType; | ||
|
||
final class WeekdayType extends StringType | ||
{ | ||
/** @codeCoverageIgnore */ | ||
public function getName(): string | ||
{ | ||
return 'dtp_weekday'; | ||
} | ||
|
||
/** @param Weekday|null $value */ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
return $value->value; | ||
} | ||
|
||
/** @param string|null $value */ | ||
public function convertToPHPValue($value, AbstractPlatform $platform): ?Weekday | ||
{ | ||
return $value === null | ||
? null | ||
: Weekday::from($value); | ||
} | ||
|
||
/** @codeCoverageIgnore */ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | ||
{ | ||
$column['length'] = 9; | ||
|
||
return $platform->getStringTypeDeclarationSQL($column); | ||
} | ||
|
||
/** @codeCoverageIgnore */ | ||
public function requiresSQLCommentHint(AbstractPlatform $platform): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimePrecision\Doctrine; | ||
|
||
use DigitalCraftsman\DateTimePrecision\Weekdays; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\JsonType; | ||
|
||
final class WeekdaysType extends JsonType | ||
{ | ||
/** @codeCoverageIgnore */ | ||
public function getName(): string | ||
{ | ||
return 'dtp_weekdays'; | ||
} | ||
|
||
/** @param Weekdays|null $value */ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
$array = $value->normalize(); | ||
|
||
return json_encode($array, JSON_THROW_ON_ERROR); | ||
} | ||
|
||
/** @param string|null $value */ | ||
public function convertToPHPValue($value, AbstractPlatform $platform): ?Weekdays | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
$array = json_decode($value, true, 512, JSON_THROW_ON_ERROR); | ||
|
||
return Weekdays::denormalize($array); | ||
} | ||
|
||
/** @codeCoverageIgnore */ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | ||
{ | ||
$column['jsonb'] = true; | ||
|
||
return $platform->getJsonTypeDeclarationSQL($column); | ||
} | ||
|
||
/** @codeCoverageIgnore */ | ||
public function requiresSQLCommentHint(AbstractPlatform $platform): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.