Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/77344
Change subject: Imrpovements to GUID generation code [do not submit]
......................................................................
Imrpovements to GUID generation code [do not submit]
Change-Id: I8a8c9dfcd33afc0b59398ebfd302e2aa290342bd
---
M lib/WikibaseLib.classes.php
A lib/includes/ClaimGuidGenerator.php
M lib/includes/GuidGenerator.php
A lib/includes/V4GuidGenerator.php
A lib/tests/phpunit/ClaimGuidGeneratorTest.php
5 files changed, 129 insertions(+), 149 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/44/77344/1
diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index 4f4b844..2e0741f 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -43,10 +43,10 @@
'Wikibase\LanguageFallbackChainFactory' =>
'includes/LanguageFallbackChainFactory.php',
'Wikibase\LanguageWithConversion' =>
'includes/LanguageWithConversion.php',
'Wikibase\Lib\GuidGenerator' => 'includes/GuidGenerator.php',
- 'Wikibase\Lib\V4GuidGenerator' => 'includes/GuidGenerator.php',
+ 'Wikibase\Lib\V4GuidGenerator' =>
'includes/V4GuidGenerator.php',
'Wikibase\Lib\EntityRetrievingDataTypeLookup' =>
'includes/EntityRetrievingDataTypeLookup.php',
'Wikibase\Lib\PropertyInfoDataTypeLookup' =>
'includes/PropertyInfoDataTypeLookup.php',
- 'Wikibase\Lib\ClaimGuidGenerator' =>
'includes/GuidGenerator.php',
+ 'Wikibase\Lib\ClaimGuidGenerator' =>
'includes/ClaimGuidGenerator.php',
'Wikibase\Lib\ClaimGuidValidator' =>
'includes/ClaimGuidValidator.php',
'Wikibase\Lib\InMemoryDataTypeLookup' =>
'includes/InMemoryDataTypeLookup.php',
'Wikibase\LibRegistry' => 'includes/LibRegistry.php',
diff --git a/lib/includes/ClaimGuidGenerator.php
b/lib/includes/ClaimGuidGenerator.php
new file mode 100644
index 0000000..7318b80
--- /dev/null
+++ b/lib/includes/ClaimGuidGenerator.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Wikibase\Lib;
+
+use InvalidArgumentException;
+
+/**
+ * Claim GUID generator.
+ *
+ * @since 0.3
+ *
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ClaimGuidGenerator implements GuidGenerator {
+
+ /**
+ * @since 0.3
+ *
+ * @var GuidGenerator
+ */
+ protected $baseGenerator;
+
+ protected $entityIdString;
+
+ /**
+ * @param string $entityIdString
+ *
+ * @throws InvalidArgumentException
+ */
+ public function __construct( $entityIdString ) {
+ if ( !is_string( $entityIdString ) ) {
+ throw new InvalidArgumentException( '$entityIdString
needs to be a string' );
+ }
+
+ $this->entityIdString = $entityIdString;
+ $this->baseGenerator = new V4GuidGenerator();
+ }
+
+ /**
+ * Generates and returns a GUID.
+ * @see http://php.net/manual/en/function.com-create-guid.php
+ * @see GuidGenerator::newGuid
+ *
+ * @since 0.3
+ *
+ * @return string
+ */
+ public function newGuid() {
+ return $this->entityIdString . '$' .
$this->baseGenerator->newGuid();
+ }
+
+}
diff --git a/lib/includes/GuidGenerator.php b/lib/includes/GuidGenerator.php
index 4106d7f..a40ebc1 100644
--- a/lib/includes/GuidGenerator.php
+++ b/lib/includes/GuidGenerator.php
@@ -5,21 +5,6 @@
/**
* Globally Unique IDentifier generator.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
* @since 0.3
*
* @file
@@ -38,137 +23,5 @@
* @return string
*/
public function newGuid();
-
-}
-
-/**
- * Globally Unique IDentifier generator.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @since 0.3
- *
- * @file
- * @ingroup WikibaseLib
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class V4GuidGenerator implements GuidGenerator {
-
- /**
- * Generates and returns a GUID.
- * @see http://php.net/manual/en/function.com-create-guid.php
- * @see GuidGenerator::newGuid
- *
- * @since 0.3
- *
- * @return string
- */
- public function newGuid() {
- if ( function_exists( 'com_create_guid' ) ) {
- return trim( com_create_guid(), '{}' );
- }
-
- return sprintf(
- '%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
- mt_rand( 0, 65535 ),
- mt_rand( 0, 65535 ),
- mt_rand( 0, 65535 ),
- mt_rand( 16384, 20479 ),
- mt_rand( 32768, 49151 ),
- mt_rand( 0, 65535 ),
- mt_rand( 0, 65535 ),
- mt_rand( 0, 65535 )
- );
- }
-
-}
-
-use MWException;
-use Wikibase\EntityId;
-
-/**
- * Claim GUID generator.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @since 0.3
- *
- * @file
- * @ingroup WikibaseLib
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class ClaimGuidGenerator implements GuidGenerator {
-
- /**
- * @since 0.3
- *
- * @var GuidGenerator
- */
- protected $baseGenerator;
-
- /**
- * @since 0.3
- *
- * @var EntityId|null
- */
- protected $entityId;
-
- /**
- * Constructor.
- *
- * @since 0.3
- */
- public function __construct( EntityId $entityId = null ) {
- $this->baseGenerator = new V4GuidGenerator();
- $this->entityId = $entityId;
- }
-
- /**
- * Generates and returns a GUID.
- * @see http://php.net/manual/en/function.com-create-guid.php
- * @see GuidGenerator::newGuid
- *
- * @since 0.3
- *
- * @return string
- * @throws MWException
- */
- public function newGuid() {
- if ( $this->entityId === null ) {
- throw new MWException( 'Entity ID needs to be set
before a Claim GUID can be generated' );
- }
-
- return $this->entityId->getPrefixedId() . '$' .
$this->baseGenerator->newGuid();
- }
}
diff --git a/lib/includes/V4GuidGenerator.php b/lib/includes/V4GuidGenerator.php
new file mode 100644
index 0000000..2893025
--- /dev/null
+++ b/lib/includes/V4GuidGenerator.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Wikibase\Lib;
+
+/**
+ * Globally Unique IDentifier generator.
+ *
+ * @since 0.3
+ *
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class V4GuidGenerator implements GuidGenerator {
+
+ /**
+ * Generates and returns a GUID.
+ * @see http://php.net/manual/en/function.com-create-guid.php
+ * @see GuidGenerator::newGuid
+ *
+ * @since 0.3
+ *
+ * @return string
+ */
+ public function newGuid() {
+ if ( function_exists( 'com_create_guid' ) ) {
+ return trim( com_create_guid(), '{}' );
+ }
+
+ return sprintf(
+ '%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
+ mt_rand( 0, 65535 ),
+ mt_rand( 0, 65535 ),
+ mt_rand( 0, 65535 ),
+ mt_rand( 16384, 20479 ),
+ mt_rand( 32768, 49151 ),
+ mt_rand( 0, 65535 ),
+ mt_rand( 0, 65535 ),
+ mt_rand( 0, 65535 )
+ );
+ }
+
+}
diff --git a/lib/tests/phpunit/ClaimGuidGeneratorTest.php
b/lib/tests/phpunit/ClaimGuidGeneratorTest.php
new file mode 100644
index 0000000..747e807
--- /dev/null
+++ b/lib/tests/phpunit/ClaimGuidGeneratorTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Wikibase\Lib\Test;
+
+use Wikibase\Lib\ClaimGuidGenerator;
+
+/**
+ * @covers Wikibase\Lib\ClaimGuidGenerator
+ *
+ * @file
+ * @since 0.4
+ *
+ * @ingroup Wikibase
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ClaimGuidGeneratorTest extends \PHPUnit_Framework_TestCase {
+
+ // TODO
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/77344
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a8c9dfcd33afc0b59398ebfd302e2aa290342bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits