Вход Регистрация
Файл: vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php
Строк: 58
<?php

namespace DoctrineDBALTypes;

use 
DateTime;
use 
DateTimeInterface;
use 
DoctrineDBALPlatformsAbstractPlatform;

use function 
date_create;

/**
 * Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object.
 */
class DateTimeType extends Type implements PhpDateTimeMappingType
{
    
/**
     * {@inheritdoc}
     */
    
public function getName()
    {
        return 
Types::DATETIME_MUTABLE;
    }

    
/**
     * {@inheritdoc}
     */
    
public function getSQLDeclaration(array $columnAbstractPlatform $platform)
    {
        return 
$platform->getDateTimeTypeDeclarationSQL($column);
    }

    
/**
     * {@inheritdoc}
     */
    
public function convertToDatabaseValue($valueAbstractPlatform $platform)
    {
        if (
$value === null) {
            return 
$value;
        }

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

        throw 
ConversionException::conversionFailedInvalidType($value$this->getName(), ['null''DateTime']);
    }

    
/**
     * {@inheritdoc}
     */
    
public function convertToPHPValue($valueAbstractPlatform $platform)
    {
        if (
$value === null || $value instanceof DateTimeInterface) {
            return 
$value;
        }

        
$val DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);

        if (! 
$val) {
            
$val date_create($value);
        }

        if (! 
$val) {
            throw 
ConversionException::conversionFailedFormat(
                
$value,
                
$this->getName(),
                
$platform->getDateTimeFormatString()
            );
        }

        return 
$val;
    }
}
Онлайн: 0
Реклама