devleand/doctrine-dbal-timestamp-type

Doctrine DBAL 的时间戳类型

0.1.1 2022-01-08 16:08 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:25:49 UTC


README

为 Doctrine DBAL 提供跨平台时间戳支持的库。

它是如何工作的?

时间戳类型继承自 Doctrine DateTime 类型。在保存/检索值时,它会将该值转换为 UTC 格式的日期。因此,对于不支持时间戳类型的平台,通过在日期时间字段中以 UTC 格式存储值来实现支持。

安装

composer require devleand/doctrine-dbal-timestamp-type

并将类型添加到 Doctrine\DBAL

\Doctrine\DBAL\Types\Type::addType('timestamp', 'Devleand\Doctrine\DBAL\Types\TimestampType');

Symfony

将以下内容添加到 config/packages/doctrine.yaml

doctrine:
    dbal:
        types:
            timestamp: Devleand\Doctrine\DBAL\Types\TimestampType
        mapping_types:
            timestamp: timestamp

完整文件内容的示例

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        types:
            timestamp: Devleand\Doctrine\DBAL\Types\TimestampType
        mapping_types:
            timestamp: timestamp

    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App