From 2eaf153ce4b09a540d56b4583030e1192b2afdf3 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 17 Jan 2014 16:37:51 -0600 Subject: [PATCH] Add the getHex() method --- src/Rhumsaa/Uuid/Uuid.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Rhumsaa/Uuid/Uuid.php b/src/Rhumsaa/Uuid/Uuid.php index 99a10a0..a130d75 100644 --- a/src/Rhumsaa/Uuid/Uuid.php +++ b/src/Rhumsaa/Uuid/Uuid.php @@ -231,11 +231,8 @@ final class Uuid { $bytes = ''; - $hex = $this->toString(); - $hex = str_replace('-', '', $hex); - foreach (range(-2, -32, 2) as $step) { - $bytes = chr(hexdec(substr($hex, $step, 2))) . $bytes; + $bytes = chr(hexdec(substr($this->getHex(), $step, 2))) . $bytes; } return $bytes; @@ -423,6 +420,16 @@ final class Uuid return $this->fields; } + /** + * Returns the hexadecimal value of the UUID + * + * @return string + */ + public function getHex() + { + return str_replace('-', '', $this->toString()); + } + /** * Returns the integer value of the UUID, represented as a BigNumber * @@ -440,11 +447,8 @@ final class Uuid ); } - $hex = $this->toString(); - $hex = str_replace('-', '', $hex); - $number = \Moontoast\Math\BigNumber::baseConvert( - $hex, + $this->getHex(), 16, 10 );