-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php declare(strict_types = 1); | ||
/** | ||
* This file is part of the Dogma library (https://github.com/paranoiq/dogma) | ||
* | ||
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq) | ||
* | ||
* For the full copyright and license information read the file 'license.md', distributed with this source code | ||
*/ | ||
|
||
namespace Dogma\Doctrine\Time; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\IntegerType; | ||
use Dogma\Time\DayOfYear; | ||
|
||
class DayOfYearType extends IntegerType | ||
{ | ||
|
||
public const NAME = 'day_of_year'; | ||
|
||
public function getName(): string | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* @param \Dogma\Time\DayOfYear|int|null $value | ||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform | ||
* @return \Dogma\Time\DayOfYear|null | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform): ?DayOfYear | ||
{ | ||
if ($value === null || $value instanceof DayOfYear) { | ||
return $value; | ||
} | ||
|
||
return new DayOfYear((int) $value); | ||
} | ||
|
||
/** | ||
* @param \Dogma\Time\DayOfYear|int|null $value | ||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform | ||
* @return int|null | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int | ||
{ | ||
return $value instanceof DayOfYear ? $value->getNumber() : $value; | ||
} | ||
|
||
public function requiresSQLCommentHint(AbstractPlatform $platform): bool | ||
{ | ||
return true; | ||
} | ||
|
||
} |