doctrineum/datetime-immutable

该包已被废弃,不再维护。作者建议使用doctrine/dbal包。

DateTimeImmutable作为Doctrine的类型 - 已废弃,因为doctrine/dbal已实现此功能

2.1.0 2018-07-18 07:59 UTC

This package is auto-updated.

Last update: 2022-02-01 12:57:16 UTC


README

Test Coverage License

已废弃

请使用Doctrine\DBAL\Types\DateTimeImmuable代替。

你是否需要它?

  • 首先,如果需要在应用程序中添加新类型,请三思。
  • 另一方面,任何时间的不变对象可以为您节省许多问题和时间...

使用方法

  • 注册
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf();
  • 使用
use Doctrine\ORM\Mapping as ORM;

class Foo {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;
    /**
     * @ORM\Column(type="datetime-immutable")
     */
    private $when;
    
    public function __construct(\DateTimeImmutable $when)
    {
        $this->when = $when;
    }
}
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf();

$foo = new Foo(new \DateTimeImmutable());
// ...
$entityManager->persist($foo);
$entityManager->flush();

常见错误

注意时区不被持久化,因此在获取时无法恢复。Doctrine使用服务器默认时区。有关详细信息,尤其是解决方案,请参阅Doctrine文档