From 305e330d6aca329475779e08770bfe401ff4fbe5 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 11 Oct 2017 22:48:12 +0200 Subject: [PATCH] Add support for Doctrine immutable date types --- lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php | 4 ++++ lib/Gedmo/Timestampable/Mapping/Driver/Xml.php | 4 ++++ lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php | 4 ++++ lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php | 3 +++ lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php | 3 +++ 5 files changed, 18 insertions(+) diff --git a/lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php b/lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php index 418594c668..bfd2a4608f 100644 --- a/lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php +++ b/lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php @@ -28,9 +28,13 @@ class Annotation extends AbstractAnnotationDriver */ protected $validTypes = array( 'date', + 'date_immutable', 'time', + 'time_immutable', 'datetime', + 'datetime_immutable', 'datetimetz', + 'datetimetz_immutable', 'timestamp', 'zenddate', 'vardatetime', diff --git a/lib/Gedmo/Timestampable/Mapping/Driver/Xml.php b/lib/Gedmo/Timestampable/Mapping/Driver/Xml.php index b63c9fc2c0..a67c6c242f 100644 --- a/lib/Gedmo/Timestampable/Mapping/Driver/Xml.php +++ b/lib/Gedmo/Timestampable/Mapping/Driver/Xml.php @@ -24,9 +24,13 @@ class Xml extends BaseXml */ private $validTypes = array( 'date', + 'date_immutable', 'time', + 'time_immutable', 'datetime', + 'datetime_immutable', 'datetimetz', + 'datetimetz_immutable', 'timestamp', 'zenddate', 'vardatetime', diff --git a/lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php b/lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php index 8bf2f8280b..558b996840 100644 --- a/lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php +++ b/lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php @@ -30,9 +30,13 @@ class Yaml extends File implements Driver */ private $validTypes = array( 'date', + 'date_immutable', 'time', + 'time_immutable', 'datetime', + 'datetime_immutable', 'datetimetz', + 'datetimetz_immutable', 'timestamp', 'zenddate', 'vardatetime', diff --git a/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php b/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php index 1fd4bc0780..d23a43277d 100644 --- a/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php +++ b/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php @@ -26,6 +26,9 @@ public function getDateValue($meta, $field) if (isset($mapping['type']) && $mapping['type'] == 'zenddate') { return new \Zend_Date(); } + if (isset($mapping['type']) && in_array($mapping['type'], array('date_immutable', 'time_immutable', 'datetime_immutable', 'datetimetz_immutable'), true)) { + return new \DateTimeImmutable(); + } return \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', '')) ->setTimeZone(new \DateTimeZone(date_default_timezone_get())); diff --git a/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php b/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php index 6285674c3f..f8333905f6 100644 --- a/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php +++ b/lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php @@ -26,6 +26,9 @@ public function getDateValue($meta, $field) if (isset($mapping['type']) && $mapping['type'] == 'zenddate') { return new \Zend_Date(); } + if (isset($mapping['type']) && in_array($mapping['type'], array('date_immutable', 'time_immutable', 'datetime_immutable', 'datetimetz_immutable'), true)) { + return new \DateTimeImmutable(); + } return \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', '')) ->setTimeZone(new \DateTimeZone(date_default_timezone_get()));