mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Adding code to detect whether this is a 32-bit or 64-bit PHP build
This commit is contained in:
@@ -8,6 +8,18 @@ A PHP 5.3+ library for generating and working with [RFC 4122][rfc4122] version
|
||||
Much inspiration for this library came from the [Java][javauuid] and
|
||||
[Python][pyuuid] UUID libraries.
|
||||
|
||||
## Requirements
|
||||
|
||||
Rhumsaa\Uuid works on 64-bit builds of PHP 5.3.3+.
|
||||
|
||||
Since, this library deals with large integers, so you will need to run it on a
|
||||
64-bit system with a 64-bit compiled version of PHP.
|
||||
|
||||
**Warning:** The [Windows binaries located on PHP.net][phpwin] are 32-bit
|
||||
versions of PHP. Even if you run them on a 64-bit version of Windows, this
|
||||
library will not work. You will need to compile PHP on Windows yourself to
|
||||
build a 64-bit version.
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
@@ -51,4 +63,5 @@ and install the latest version of the Uuid library into your project:
|
||||
[rfc4122]: http://tools.ietf.org/html/rfc4122
|
||||
[javauuid]: http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html
|
||||
[pyuuid]: http://docs.python.org/library/uuid.html
|
||||
[phpwin]: http://windows.php.net/download/
|
||||
[packagist]: http://packagist.org/
|
||||
|
||||
@@ -97,6 +97,13 @@ final class Uuid
|
||||
*/
|
||||
protected function __construct($msb, $lsb)
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
throw new \OverflowException(
|
||||
'Attempting to create a UUID on a 32-bit build of PHP. This '
|
||||
. 'library requires a 64-bit build of PHP.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->msb = $msb;
|
||||
$this->lsb = $lsb;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Rhumsaa\Uuid;
|
||||
|
||||
/**
|
||||
* This class tests the environment to ensure the library functions as designed
|
||||
* on 32-bit and 64-bit environments.
|
||||
*/
|
||||
class EnvironmentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Rhumsaa\Uuid\Uuid::__construct
|
||||
*/
|
||||
public function testConstructorException()
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
|
||||
$this->setExpectedException(
|
||||
'OverflowException',
|
||||
'Attempting to create a UUID on a 32-bit build of PHP. This library requires a 64-bit build of PHP.'
|
||||
);
|
||||
|
||||
$uuid = Uuid::uuid1();
|
||||
|
||||
} else {
|
||||
|
||||
$this->markTestSkipped('This test is only applicable on a 32-bit system.');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,16 @@ namespace Rhumsaa\Uuid;
|
||||
|
||||
class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
// Skip these tests if run on a 32-bit build of PHP
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->markTestSkipped(
|
||||
'Running tests on a 32-bit build of PHP; 64-bit build required.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Rhumsaa\Uuid\Uuid::fromString
|
||||
* @covers Rhumsaa\Uuid\Uuid::__construct
|
||||
|
||||
Reference in New Issue
Block a user