Skip to content

Commit

Permalink
Merge pull request #10 from robinvdvleuten/master
Browse files Browse the repository at this point in the history
Added support for both ramsey/uuid 2.0 and 3.0
  • Loading branch information
wjzijderveld authored Dec 6, 2016
2 parents 9358547 + 1777d91 commit 19b3299
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- hhvm-nightly

matrix:
include:
- php: 7.0
env: UUID_VERSION='~2.0'
- php: 7.0
env: UUID_VERSION='~3.0'
allow_failures:
- php: hhvm-nightly

install: composer install
before_install:
- if [ "$UUID_VERSION" != "" ]; then composer require --dev --no-update ramsey/uuid=$UUID_VERSION; fi

install:
- composer update --prefer-dist
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"symfony/http-kernel": "~2.1|~3.0",
"symfony/http-foundation": "~2.1|~3.0",
"ramsey/uuid": "~2.0"
"ramsey/uuid": "~2.0|~3.0"
},
"authors": [
{
Expand Down
24 changes: 22 additions & 2 deletions src/Qandidate/Stack/UuidRequestIdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Qandidate\Stack;

use Rhumsaa\Uuid\Uuid;
use LogicException;

/**
* Generates a uuid for the request id.
Expand All @@ -20,19 +20,39 @@ class UuidRequestIdGenerator implements RequestIdGenerator
{
private $nodeId;

private $className;

/**
* @param null|string|integer $nodeId
* @param null|string $className
*/
public function __construct($nodeId = null)
{
$this->nodeId = $nodeId;
$this->className = $this->getClassName();
}

/**
* {@inheritDoc}
*/
public function generate()
{
return Uuid::uuid1($this->nodeId)->toString();
return call_user_func([$this->className, 'uuid1'], $this->nodeId)->toString();
}

/**
* @return string
*/
private function getClassName()
{
if (class_exists('Ramsey\Uuid\Uuid')) {
return '\Ramsey\Uuid\Uuid';
}

if (class_exists('Rhumsaa\Uuid\Uuid')) {
return '\Rhumsaa\Uuid\Uuid';
}

throw new LogicException('UuidRequestIdGenerator requires library ramsey/uuid.');
}
}

0 comments on commit 19b3299

Please sign in to comment.