Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from IcecaveStudios/feature/tostring
Browse files Browse the repository at this point in the history
Added __toString() to UuidInterface. Fixes #7
  • Loading branch information
jmalloc committed Nov 17, 2014
2 parents 3121fae + a0a9d39 commit e84ed03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Uuid.php
Expand Up @@ -221,6 +221,16 @@ public function string()
);
}

/**
* Generate a string representation of this UUID.
*
* @return string A string representation of this UUID in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
*/
public function __toString()
{
return $this->string();
}

/**
* Get the raw binary representation of this UUID.
*
Expand Down
7 changes: 7 additions & 0 deletions src/UuidInterface.php
Expand Up @@ -92,6 +92,13 @@ public function nodeLow();
*/
public function string();

/**
* Generate a string representation of this UUID.
*
* @return string A string representation of this UUID in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
*/
public function __toString();

/**
* Get the raw binary representation of this UUID.
*
Expand Down
5 changes: 5 additions & 0 deletions test/suite/UuidTest.php
Expand Up @@ -109,6 +109,11 @@ public function testString()
$this->assertSame('01234567-89ab-cdef-fedc-ba9876543210', $this->uuid->string());
}

public function testToString()
{
$this->assertSame('01234567-89ab-cdef-fedc-ba9876543210', strval($this->uuid));
}

public function testBytes()
{
$this->assertSame("\x01\x23\x45\x67\x89\xab\xcd\xef\xfe\xdc\xba\x98\x76\x54\x32\x10", $this->uuid->bytes());
Expand Down

0 comments on commit e84ed03

Please sign in to comment.