-
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.
copy DateTimeType and DateType from Psc but use the Webforge\Common\D…
…ateTime
- Loading branch information
Showing
2 changed files
with
68 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,34 @@ | ||
<?php | ||
|
||
namespace Webforge\Doctrine\Types; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Webforge\Common\DateTime\DateTime; | ||
|
||
class DateTimeType extends \Doctrine\DBAL\Types\DateTimeType { | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) { | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
$val = DateTime::parse($platform->getDateTimeFormatString(), $value); | ||
if (!$val) { | ||
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); | ||
} | ||
|
||
return $val; | ||
} | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { | ||
return sprintf("%s COMMENT '%s' ", | ||
parent::getSQLDeclaration($fieldDeclaration, $platform), | ||
$platform->getDoctrineTypeComment($this) | ||
); | ||
} | ||
|
||
public function getName() { | ||
return 'WebforgeDateTime'; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Webforge\Doctrine\Types; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Webforge\Common\DateTime\Date; | ||
|
||
class DateType extends \Doctrine\DBAL\Types\DateType { | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) { | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
$val = Date::parse($platform->getDateFormatString(), $value); | ||
if (!$val) { | ||
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); | ||
} | ||
|
||
return $val; | ||
} | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { | ||
return sprintf("%s COMMENT '%s' ", | ||
parent::getSQLDeclaration($fieldDeclaration, $platform), | ||
$platform->getDoctrineTypeComment($this) | ||
); | ||
} | ||
|
||
public function getName() { | ||
return 'WebforgeDate'; | ||
} | ||
} |