diff --git a/library/Rhumsaa/Uuid/Uuid.php b/library/Rhumsaa/Uuid/Uuid.php index 40e56ff..e293ba2 100644 --- a/library/Rhumsaa/Uuid/Uuid.php +++ b/library/Rhumsaa/Uuid/Uuid.php @@ -185,6 +185,24 @@ final class Uuid return new \DateTime('@' . number_format($unixTime, 0, '', '')); } + /** + * Returns an array of the fields of this UUID, with keys named according + * to the RFC 4122 names for the fields. + * + * @return array + */ + public function getFields() + { + return array( + 'time_low' => $this->getTimeLow(), + 'time_mid' => $this->getTimeMid(), + 'time_hi_and_version' => $this->getTimeHiAndVersion(), + 'clock_seq_hi_and_reserved' => $this->getClockSeqHiAndReserved(), + 'clock_seq_low' => $this->getClockSeqLow(), + 'node' => $this->getNode(), + ); + } + /** * Returns the least significant 64 bits of this UUID's 128 bit value * diff --git a/tests/Rhumsaa/Uuid/UuidTest.php b/tests/Rhumsaa/Uuid/UuidTest.php index e639b00..37eb887 100644 --- a/tests/Rhumsaa/Uuid/UuidTest.php +++ b/tests/Rhumsaa/Uuid/UuidTest.php @@ -99,6 +99,20 @@ class UuidTest extends \PHPUnit_Framework_TestCase $date = $uuid->getDateTime(); } + /** + * @covers Rhumsaa\Uuid\Uuid::getFields + */ + public function testGetFields() + { + $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); + $this->assertArrayHasKey('time_low', $uuid->getFields()); + $this->assertArrayHasKey('time_mid', $uuid->getFields()); + $this->assertArrayHasKey('time_hi_and_version', $uuid->getFields()); + $this->assertArrayHasKey('clock_seq_hi_and_reserved', $uuid->getFields()); + $this->assertArrayHasKey('clock_seq_low', $uuid->getFields()); + $this->assertArrayHasKey('node', $uuid->getFields()); + } + /** * @covers Rhumsaa\Uuid\Uuid::getLeastSignificantBits */