mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
Adding getFields() method to return array of fields.
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user