mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-16 16:17:43 +03:00
Extract factory interface & add basic pecl impl
This commit is contained in:
@@ -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
@@ -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
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user