Skip to content

Instantly share code, notes, and snippets.

@MichaelGooden
Created June 15, 2017 07:53
Show Gist options
  • Save MichaelGooden/4a14455dc657b837320846c74874d048 to your computer and use it in GitHub Desktop.
Save MichaelGooden/4a14455dc657b837320846c74874d048 to your computer and use it in GitHub Desktop.
Time-ordered COMB UUIDs with Ramsey\UUID and Zend Framework 2/3 MVC
<?php
namespace Domain;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
use Ramsey\Uuid\FeatureSet;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
use Zend\EventManager\EventInterface;
class Module
{
public function getConfig()
{
return include __DIR__.'/../config/module.config.php';
}
public function onBootstrap(EventInterface $e)
{
$featureSet = new FeatureSet();
$factory = new UuidFactory();
$codec = new TimestampFirstCombCodec($factory->getUuidBuilder());
$generator = new CombGenerator($featureSet->getRandomGenerator(), $featureSet->getNumberConverter());
$factory->setCodec($codec);
$factory->setRandomGenerator($generator);
Uuid::setFactory($factory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment