Created
June 15, 2017 07:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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