Skip to content

Commit

Permalink
Add DayOfYearType
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Jul 10, 2019
1 parent 4df95a3 commit 9e0afcb
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Time/DayOfYearType.php
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;
}

}

0 comments on commit 9e0afcb

Please sign in to comment.