Extract factory interface & add basic pecl impl

This commit is contained in:
Thibaud Fabre
2014-12-17 01:30:45 +01:00
parent ec8d7a739c
commit b8fe2e4a91
3 changed files with 96 additions and 1 deletions
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace Rhumsaa\Uuid;
class PeclUuidFactory implements UuidFactoryInterface
{
private $factory;
public function __construct(UuidFactoryInterface $factory)
{
$this->factory = $factory;
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid1()
*/
public function uuid1($node = null, $clockSeq = null)
{
$uuid = uuid_create(UUID_TYPE_TIME);
return $this->fromString($uuid);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid3()
*/
public function uuid3($ns, $name)
{
return $this->factory->uuid3($ns, $name);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid4()
*/
public function uuid4()
{
$uuid = uuid_create(UUID_TYPE_RANDOM);
return $this->fromString($uuid);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid5()
*/
public function uuid5($ns, $name)
{
return $this->factory->uuid5($ns, $name);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromBytes()
*/
public function fromBytes($bytes)
{
return $this->factory->fromBytes($bytes);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromString()
*/
public function fromString($name)
{
return $this->factory->fromString($name);
}
/*
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromInteger()
*/
public function fromInteger($integer)
{
return $this->factory->fromInteger($integer);
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ use Rhumsaa\Uuid\Converter\TimeConverterInterface;
use Rhumsaa\Uuid\Provider\NodeProviderInterface;
use Rhumsaa\Uuid\Provider\TimeProviderInterface;
class UuidFactory
class UuidFactory implements UuidFactoryInterface
{
/**
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Rhumsaa\Uuid;
interface UuidFactoryInterface
{
public function uuid1($node = null, $clockSeq = null);
public function uuid3($ns, $name);
public function uuid4();
public function uuid5($ns, $name);
public function fromBytes($bytes);
public function fromString($name);
public function fromInteger($integer);
}