Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Database/DBAL/TimestampType.php
Строк: 108
<?php

namespace IlluminateDatabaseDBAL;

use 
DoctrineDBALException as DBALException;
use 
DoctrineDBALPlatformsAbstractPlatform;
use 
DoctrineDBALPlatformsMariaDb1010Platform;
use 
DoctrineDBALPlatformsMariaDb1027Platform;
use 
DoctrineDBALPlatformsMariaDb1052Platform;
use 
DoctrineDBALPlatformsMariaDb1060Platform;
use 
DoctrineDBALPlatformsMariaDBPlatform;
use 
DoctrineDBALPlatformsMySQL57Platform;
use 
DoctrineDBALPlatformsMySQL80Platform;
use 
DoctrineDBALPlatformsMySQL84Platform;
use 
DoctrineDBALPlatformsMySQLPlatform;
use 
DoctrineDBALPlatformsPostgreSQL100Platform;
use 
DoctrineDBALPlatformsPostgreSQL120Platform;
use 
DoctrineDBALPlatformsPostgreSQL94Platform;
use 
DoctrineDBALPlatformsPostgreSQLPlatform;
use 
DoctrineDBALPlatformsSqlitePlatform;
use 
DoctrineDBALPlatformsSQLServer2012Platform;
use 
DoctrineDBALPlatformsSQLServerPlatform;
use 
DoctrineDBALTypesPhpDateTimeMappingType;
use 
DoctrineDBALTypesType;

class 
TimestampType extends Type implements PhpDateTimeMappingType
{
    
/**
     * {@inheritdoc}
     *
     * @throws DBALException
     */
    
public function getSQLDeclaration(array $columnAbstractPlatform $platform): string
    
{
        return 
match (get_class($platform)) {
            
MySQLPlatform::class,
            
MySQL57Platform::class,
            
MySQL80Platform::class,
            
MySQL84Platform::class,
            
MariaDBPlatform::class,
            
MariaDb1027Platform::class,
            
MariaDb1052Platform::class,
            
MariaDb1060Platform::class,
            
MariaDb1010Platform::class => $this->getMySqlPlatformSQLDeclaration($column),
            
PostgreSQLPlatform::class,
            
PostgreSQL94Platform::class,
            
PostgreSQL100Platform::class,
            
PostgreSQL120Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
            
SQLServerPlatform::class,
            
SQLServer2012Platform::class => $this->getSqlServerPlatformSQLDeclaration($column),
            
SqlitePlatform::class => 'DATETIME',
            default => throw new 
DBALException('Invalid platform: '.substr(strrchr(get_class($platform), '\'), 1)),
        };
    }

    /**
     * Get the SQL declaration for MySQL.
     *
     * @param  array  $column
     * @return string
     */
    protected function getMySqlPlatformSQLDeclaration(array $column): string
    {
        $columnType = '
TIMESTAMP';

        if ($column['
precision']) {
            $columnType = '
TIMESTAMP('.min((int) $column['precision'], 6).')';
        }

        $notNull = $column['
notnull'] ?? false;

        if (! $notNull) {
            return $columnType.' 
NULL';
        }

        return $columnType;
    }

    /**
     * Get the SQL declaration for PostgreSQL.
     *
     * @param  array  $column
     * @return string
     */
    protected function getPostgresPlatformSQLDeclaration(array $column): string
    {
        return '
TIMESTAMP('.min((int) $column['precision'], 6).')';
    }

    /**
     * Get the SQL declaration for SQL Server.
     *
     * @param  array  $column
     * @return string
     */
    protected function getSqlServerPlatformSQLDeclaration(array $column): string
    {
        return $column['
precision'] ?? false
            ? '
DATETIME2('.min((int) $column['precision'], 7).')'
            : '
DATETIME';
    }

    /**
     * {@inheritdoc}
     *
     * @return string
     */
    public function getName()
    {
        return '
timestamp';
    }
}
Онлайн: 1
Реклама