From b8fe2e4a918cbb072efea4e435f53006bfb577ee Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 17 Dec 2014 01:30:45 +0100 Subject: [PATCH] Extract factory interface & add basic pecl impl --- src/PeclUuidFactory.php | 74 ++++++++++++++++++++++++++++++++++++ src/UuidFactory.php | 2 +- src/UuidFactoryInterface.php | 21 ++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/PeclUuidFactory.php create mode 100644 src/UuidFactoryInterface.php diff --git a/src/PeclUuidFactory.php b/src/PeclUuidFactory.php new file mode 100644 index 0000000..9cf881c --- /dev/null +++ b/src/PeclUuidFactory.php @@ -0,0 +1,74 @@ +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); + } +} \ No newline at end of file diff --git a/src/UuidFactory.php b/src/UuidFactory.php index 5919968..9885742 100644 --- a/src/UuidFactory.php +++ b/src/UuidFactory.php @@ -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 { /** diff --git a/src/UuidFactoryInterface.php b/src/UuidFactoryInterface.php new file mode 100644 index 0000000..99a743e --- /dev/null +++ b/src/UuidFactoryInterface.php @@ -0,0 +1,21 @@ +