<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vasek-purchart / doctrine-date-time-immutable-types-bundle example snippets
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class LogRow
{
// ...
/**
* @ORM/Column(type="datetime")
* @var \DateTime
*/
private $createdDate;
public function getCreatedDate(): DateTime
{
return $this->createdDate;
}
}
// created date might be modified
// even if this was not intended by the creator
// (there is no "setter" method for this on the entity)
var_dump($logRow->getCreatedDate()); // 2015-01-01 00:00:00
$logRow->getCreatedDate()->modify('+14 days');
var_dump($logRow->getCreatedDate()); // 2015-01-15 00:00:00
$product->getRenewDate()->modify('+1 year');
$entityManager->persist($product);
// no updates will be fired because Doctrine could not detect change
// (objects are compared by identity)
$entityManager->flush();
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class LogRow
{
// ...
/**
* @ORM/Column(type="datetime_immutable")
* @var \DateTimeImmutable
*/
private $createdDate;
public function getCreatedDate(): DateTimeImmutable
{
return $this->createdDate;
}
}
// created date can no longer be modified from outside
var_dump($logRow->getCreatedDate()); // 2015-01-01 00:00:00
$logRow->getCreatedDate()->modify('+14 days');
var_dump($logRow->getCreatedDate()); // 2015-01-01 00:00:00
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new VasekPurchart\DoctrineDateTimeImmutableTypesBundle\DoctrineDateTimeImmutableTypesBundle(),
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.