doctrineum / datetime-immutable
DateTimeImmutable as a type for Doctrine - abandoned as doctrine/dba already implement this
Installs: 1 468
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- doctrine/dbal: ~2.4
- doctrineum/self-registering-type: ^2.1
- granam/strict-object: ^3.0
- granam/string: ^3.0
- granam/tools: ^3.0
Requires (Dev)
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
README
Deprecated
Use Doctrine\DBAL\Types\DateTimeImmuable instead.
Do you need it?
- first of all, think twice if you need a new type into your application
- isn't Doctrine\DBAL\Types\DateTime enough?
- on the other side, immutable object of any time can save you a lot of problems and time...
Usage
- register it
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf();
- use it
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();
Common pitfalls
Be aware of timezone which is not persisted and therefore can not be restored on fetch. Doctrine uses server default timezone for it. For details and most of all, for solution, see Doctrine docs