Skip to content
Type adapter for Jiffy's Universal Timestamps on Doctrine MongoDB ODM
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitattributes
.gitignore
.scrutinizer.yml
LICENSE
README.md
composer.json

README.md

Doctrine ODM MongoDB adapter for Jiffy Universal Timestamps

Author Quality Score Software License Packagist Version Total Downloads

About the library

PHP does not offer any native class to implement timestamps with milliseconds or microseconds precision, the only "native" way to do it is working with the weird microtime function and/or the \MongoDate class.

This library provides a Doctrine ODM type to make possible using the PHP-Jiffy's UniversalTimestamp objects in our Doctrine ODM models. It's very useful if you need to deal with very precise timestamps but you don't want to couple your code with the \MongoDate class without giving up on type hinting.

As an extra bonus, this library provides future compatibility with the mongodb extension and its MongoDB\BSON\UTCDateTime class.

Installation

composer require litipk/doctrine-mongodb-jiffy

Usage

To use this type there are three steps:

  1. Install the library through Composer.
  2. Register the type in your application, if you are using Symfony, the Bundle constructor is a good place to do it.
    
    Type::registerType(
        'UniversalTimestamp',
        'Litipk\Jiffy\Doctrine\ODM\MongoDB\UniversalTimestampType'
    );
    
  3. Use the type in your models with the @UniversalTimestampField annotation.
    use Litipk\Jiffy\Doctrine\ODM\MongoDB\UniversalTimestampField;
    
    class OurDocument
    {
        /**
         * @UniversalTimestampField()
         * @var UniversalTimestamp
         */
        private $creationDate;
        
        // [...]
    }
You can’t perform that action at this time.