-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd78788
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
composer.lock* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "creof/doctrine2-php-uuid-generator", | ||
"type": "library", | ||
"description": "Doctrine2 pre-insert UUID id generator using PECL UUID package", | ||
"keywords": ["orm", "database", "id", "generator", "uuid"], | ||
"authors": [ | ||
{ | ||
"name": "Derek Lambert", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license" : "MIT", | ||
"require": { | ||
"lib-uuid": ">=1.0", | ||
"doctrine/orm": ">=2.1" | ||
}, | ||
"require-dev": { | ||
"doctrine/common": ">=2.1", | ||
"doctrine/dbal": ">=2.1", | ||
"doctrine/orm": ">=2.1@dev" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"CrEOF\\PhpUuidGenerator": "lib/" } | ||
}, | ||
"archive": { | ||
"exclude": ["!vendor", "tests", "*phpunit.xml", "composer.phar"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2013 Derek J. Lambert | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
namespace CrEOF\PhpUuidGenerator; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Id\AbstractIdGenerator; | ||
|
||
/** | ||
* UUID id generator utilizing PHP UUID library enabling pre-insert id generation | ||
* | ||
* @author Derek Lambert <[email protected]> | ||
*/ | ||
class PhpUuidGenerator extends AbstractIdGenerator | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generate(EntityManager $em, $entity) | ||
{ | ||
return uuid_create(UUID_TYPE_RANDOM); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit backupGlobals="false" | ||
colors="true" | ||
bootstrap="./tests/CrEOF/Tests/PhpUuidGenerator/TestInit.php" | ||
> | ||
|
||
<testsuites> | ||
<testsuite> | ||
<directory>./tests/CrEOF/Tests/PhpUuidGenerator</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<var name="db_type" value="pdo_pgsql"/> | ||
<var name="db_host" value="localhost" /> | ||
<var name="db_username" value="postgres" /> | ||
<var name="db_password" value="" /> | ||
<var name="db_name" value="phpuuid_tests" /> | ||
<var name="db_port" value="5432" /> | ||
|
||
<!-- Database for temporary connections (i.e. to drop/create the main database) --> | ||
<var name="tmpdb_type" value="pdo_pgsql"/> | ||
<var name="tmpdb_host" value="localhost"/> | ||
<var name="tmpdb_username" value="postgres"/> | ||
<var name="tmpdb_password" value=""/> | ||
<var name="tmpdb_name" value="doctrine_tests_tmp"/> | ||
<var name="tmpdb_port" value="5432"/> | ||
</php> | ||
</phpunit> |
53 changes: 53 additions & 0 deletions
53
tests/CrEOF/Tests/PhpUuidGenerator/PhpUuidGeneratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2012 Derek J. Lambert | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace CrEOF\Tests\PhpUuidGenerator; | ||
|
||
use CrEOF\PhpUuidGenerator\PhpUuidGenerator; | ||
|
||
/** | ||
* PhpUuidGenerator tests | ||
* | ||
* @author Derek J. Lambert <[email protected]> | ||
* @license http://dlambert.mit-license.org MIT | ||
*/ | ||
class PhpUuidGeneratorTest extends \Doctrine\Tests\OrmFunctionalTestCase | ||
{ | ||
/** | ||
* @var PhpUuidGenerator | ||
*/ | ||
protected $_generator; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->_generator = new PhpUuidGenerator(); | ||
} | ||
|
||
public function testGeneration() | ||
{ | ||
$id = $this->_generator->generate($this->_em, null); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
error_reporting(E_ALL | E_STRICT); | ||
|
||
$loader = new \Composer\Autoload\ClassLoader(); | ||
$loader->add('CrEOF\Tests\PhpUuidGenerator', __DIR__ . '/../../..'); | ||
$loader->add('Doctrine\Tests', __DIR__ . '/../../../../vendor/doctrine/orm/tests'); | ||
$loader->register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
if (!extension_loaded('uuid')) { | ||
exit("uuid extension not loaded"); | ||
} | ||
|
||
$module = 'uuid'; | ||
$functions = get_extension_funcs($module); | ||
|
||
echo "Functions available in the uuid extension:\n"; | ||
|
||
foreach ($functions as $func) { | ||
echo "$func\n"; | ||
} | ||
|
||
echo "\nConstants defined:\n"; | ||
|
||
$consts = get_defined_constants(true); | ||
|
||
print_r($consts['uuid']); | ||
|
||
$uuid = uuid_create(UUID_TYPE_RANDOM); | ||
|
||
echo "$uuid\n"; |