Adding getFields() method to return array of fields.

This commit is contained in:
Ben Ramsey
2012-07-08 17:52:16 -05:00
parent 628d93a860
commit 7cbc62a40f
2 changed files with 32 additions and 0 deletions
+18
View File
@@ -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
*
+14
View File
@@ -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
*/