jenkins-bot has submitted this change and it was merged.

Change subject: Replace manual class registration by PSR-0 based autoloading 
for the Database component
......................................................................


Replace manual class registration by PSR-0 based autoloading for the Database 
component

Change-Id: I86fdd7234a7befe4b72c5176f6e4d5462393dada
---
D Database/Database.classes.php
M Database/Database.mw.php
M Database/Database.php
A Database/compatLoader.php
R Database/includes/DBConnectionProvider.php
R Database/includes/FieldDefinition.php
R Database/includes/LazyDBConnectionProvider.php
R Database/includes/MWDB/ExtendedAbstraction.php
R Database/includes/MWDB/ExtendedMySQLAbstraction.php
R Database/includes/MediaWikiQueryInterface.php
R Database/includes/MessageReporter.php
R Database/includes/QueryInterface.php
R Database/includes/QueryInterfaceException.php
R Database/includes/ResultIterator.php
R Database/includes/TableBuilder.php
R Database/includes/TableCreationFailedException.php
R Database/includes/TableDefinition.php
M Database/tests/phpunit/FieldDefinitionTest.php
M Database/tests/phpunit/MWDB/ExtendedAbstractionTest.php
M Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
M Database/tests/phpunit/MediaWikiQueryInterfaceTest.php
M Database/tests/phpunit/ResultIteratorTest.php
M Database/tests/phpunit/TableBuilderTest.php
M Database/tests/phpunit/TableCreationFailedExceptionTest.php
M Database/tests/phpunit/TableDefinitionTest.php
M Database/tests/testLoader.php
M QueryEngine/tests/phpunit/SQLStore/Engine/EngineTest.php
27 files changed, 71 insertions(+), 107 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Database/Database.classes.php b/Database/Database.classes.php
deleted file mode 100644
index 2d25649..0000000
--- a/Database/Database.classes.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-
-/**
- * Class registration file for the Database component of Wikibase.
- *
- * 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.1
- *
- * @file
- * @ingroup WikibaseDatabase
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-return call_user_func( function() {
-
-       $classes = array(
-               'Wikibase\Database\MWDB\ExtendedAbstraction',
-               'Wikibase\Database\MWDB\ExtendedMySQLAbstraction',
-
-               'Wikibase\Database\FieldDefinition',
-               'Wikibase\Database\MediaWikiQueryInterface',
-               'Wikibase\Database\MessageReporter',
-               'Wikibase\Database\QueryInterface',
-               'Wikibase\Database\QueryInterfaceException',
-               'Wikibase\Database\ResultIterator',
-               'Wikibase\Database\TableBuilder',
-               'Wikibase\Database\TableCreationFailedException',
-               'Wikibase\Database\TableDefinition',
-       );
-
-       $paths = array();
-
-       foreach ( $classes as $class ) {
-               $path = str_replace( '\\', '/', substr( $class, 9 ) ) . '.php';
-
-               $paths[$class] = $path;
-       }
-
-       $paths['Wikibase\Repo\DBConnectionProvider'] = 
'Database/DBConnectionProvider.php';
-       $paths['Wikibase\Repo\LazyDBConnectionProvider'] = 
'Database/LazyDBConnectionProvider.php';
-
-       return $paths;
-
-} );
diff --git a/Database/Database.mw.php b/Database/Database.mw.php
index 678d4d1..d8aef41 100644
--- a/Database/Database.mw.php
+++ b/Database/Database.mw.php
@@ -32,20 +32,14 @@
        die( 'Not an entry point.' );
 }
 
-global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgAutoloadClasses, 
$wgHooks;
+global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks;
 
 //$wgExtensionCredits['other'][] = include( __DIR__ . '/DataModel.credits.php' 
);
 
 //$wgExtensionMessagesFiles['WikibaseDataModel'] = __DIR__ . 
'/DataModel.i18n.php';
 
-// Autoloading
-foreach ( include( __DIR__ . '/Database.classes.php' ) as $class => $file ) {
-       $wgAutoloadClasses[$class] = __DIR__ . '/' . $file;
-}
-
 if ( defined( 'MW_PHPUNIT_TEST' ) ) {
-       
$wgAutoloadClasses['Wikibase\Test\Database\MWDB\ExtendedAbstractionTest']
-               = __DIR__ . '/tests/phpunit/MWDB/ExtendedAbstractionTest.php';
+       require_once __DIR__ . '/tests/testLoader.php';
 }
 
 /**
diff --git a/Database/Database.php b/Database/Database.php
index 4fc978e..a702788 100644
--- a/Database/Database.php
+++ b/Database/Database.php
@@ -29,23 +29,45 @@
 
 define( 'WIKIBASE_DATABASE_VERSION', '0.1 alpha' );
 
+spl_autoload_register( function ( $className ) {
+       $className = ltrim( $className, '\\' );
+       $fileName = '';
+       $namespace = '';
+
+       if ( $lastNsPos = strripos( $className, '\\') ) {
+               $namespace = substr( $className, 0, $lastNsPos );
+               $className = substr( $className, $lastNsPos + 1 );
+               $fileName  = str_replace( '\\', '/', $namespace ) . '/';
+       }
+
+       $fileName .= str_replace( '_', '/', $className ) . '.php';
+
+       $namespaceSegments = explode( '\\', $namespace );
+
+       $inQueryEngineNamespace = count( $namespaceSegments ) > 1
+               && $namespaceSegments[0] === 'Wikibase'
+               && $namespaceSegments[1] === 'Database';
+
+       if ( $inQueryEngineNamespace ) {
+               $inTestNamespace = count( $namespaceSegments ) > 2 && 
$namespaceSegments[2] === 'Tests';
+
+               if ( !$inTestNamespace ) {
+                       $pathParts = explode( '/', $fileName );
+                       array_shift( $pathParts );
+                       array_shift( $pathParts );
+                       $fileName = implode( '/', $pathParts );
+
+                       require_once __DIR__ . '/includes/' . $fileName;
+               }
+       }
+} );
+
 // @codeCoverageIgnoreStart
 if ( defined( 'MEDIAWIKI' ) ) {
        call_user_func( function() {
                require_once __DIR__ . '/Database.mw.php';
        } );
 }
-else {
-       spl_autoload_register( function ( $className ) {
-               static $classes = false;
+// @codeCoverageIgnoreEnd
 
-               if ( $classes === false ) {
-                       $classes = include( __DIR__ . '/' . 
'Database.classes.php' );
-               }
-
-               if ( array_key_exists( $className, $classes ) ) {
-                       include_once __DIR__ . '/' . $classes[$className];
-               }
-       } );
-}
-// @codeCoverageIgnoreEnd
\ No newline at end of file
+require_once __DIR__ . '/compatLoader.php';
diff --git a/Database/compatLoader.php b/Database/compatLoader.php
new file mode 100644
index 0000000..2ddbdab
--- /dev/null
+++ b/Database/compatLoader.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Wikibase\Repo {
+
+       /**
+        * @deprecated
+        */
+       interface DBConnectionProvider extends 
\Wikibase\Database\DBConnectionProvider {}
+
+       /**
+        * @deprecated
+        */
+       class LazyDBConnectionProvider extends 
\Wikibase\Database\LazyDBConnectionProvider {}
+
+}
\ No newline at end of file
diff --git a/Database/Database/DBConnectionProvider.php 
b/Database/includes/DBConnectionProvider.php
similarity index 94%
rename from Database/Database/DBConnectionProvider.php
rename to Database/includes/DBConnectionProvider.php
index f036031..54a50b4 100644
--- a/Database/Database/DBConnectionProvider.php
+++ b/Database/includes/DBConnectionProvider.php
@@ -1,7 +1,6 @@
 <?php
 
-// TODO: fix NS
-namespace Wikibase\Repo;
+namespace Wikibase\Database;
 
 use DatabaseBase;
 
@@ -26,7 +25,7 @@
  * @since 0.1
  *
  * @file
- * @ingroup WikibaseRepo
+ * @ingroup WikibaseDatabase
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
diff --git a/Database/Database/FieldDefinition.php 
b/Database/includes/FieldDefinition.php
similarity index 100%
rename from Database/Database/FieldDefinition.php
rename to Database/includes/FieldDefinition.php
diff --git a/Database/Database/LazyDBConnectionProvider.php 
b/Database/includes/LazyDBConnectionProvider.php
similarity index 96%
rename from Database/Database/LazyDBConnectionProvider.php
rename to Database/includes/LazyDBConnectionProvider.php
index 1caf862..4dfd246 100644
--- a/Database/Database/LazyDBConnectionProvider.php
+++ b/Database/includes/LazyDBConnectionProvider.php
@@ -1,7 +1,6 @@
 <?php
 
-// TODO: fix NS
-namespace Wikibase\Repo;
+namespace Wikibase\Database;
 
 use DatabaseBase;
 
@@ -27,7 +26,7 @@
  * @since 0.1
  *
  * @file
- * @ingroup WikibaseRepo
+ * @ingroup WikibaseDatabase
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
@@ -105,4 +104,4 @@
                }
        }
 
-}
\ No newline at end of file
+}
diff --git a/Database/Database/MWDB/ExtendedAbstraction.php 
b/Database/includes/MWDB/ExtendedAbstraction.php
similarity index 98%
rename from Database/Database/MWDB/ExtendedAbstraction.php
rename to Database/includes/MWDB/ExtendedAbstraction.php
index f59865a..835046d 100644
--- a/Database/Database/MWDB/ExtendedAbstraction.php
+++ b/Database/includes/MWDB/ExtendedAbstraction.php
@@ -2,8 +2,8 @@
 
 namespace Wikibase\Database\MWDB;
 
+use Wikibase\Database\DBConnectionProvider;
 use Wikibase\Database\TableDefinition;
-use Wikibase\Repo\DBConnectionProvider;
 use InvalidArgumentException;
 use DatabaseBase;
 
diff --git a/Database/Database/MWDB/ExtendedMySQLAbstraction.php 
b/Database/includes/MWDB/ExtendedMySQLAbstraction.php
similarity index 100%
rename from Database/Database/MWDB/ExtendedMySQLAbstraction.php
rename to Database/includes/MWDB/ExtendedMySQLAbstraction.php
diff --git a/Database/Database/MediaWikiQueryInterface.php 
b/Database/includes/MediaWikiQueryInterface.php
similarity index 98%
rename from Database/Database/MediaWikiQueryInterface.php
rename to Database/includes/MediaWikiQueryInterface.php
index e575f30..b404cd0 100644
--- a/Database/Database/MediaWikiQueryInterface.php
+++ b/Database/includes/MediaWikiQueryInterface.php
@@ -2,7 +2,6 @@
 
 namespace Wikibase\Database;
 
-use Wikibase\Repo\DBConnectionProvider;
 use Wikibase\Database\TableDefinition;
 use Wikibase\Database\MWDB\ExtendedAbstraction;
 
diff --git a/Database/Database/MessageReporter.php 
b/Database/includes/MessageReporter.php
similarity index 100%
rename from Database/Database/MessageReporter.php
rename to Database/includes/MessageReporter.php
diff --git a/Database/Database/QueryInterface.php 
b/Database/includes/QueryInterface.php
similarity index 100%
rename from Database/Database/QueryInterface.php
rename to Database/includes/QueryInterface.php
diff --git a/Database/Database/QueryInterfaceException.php 
b/Database/includes/QueryInterfaceException.php
similarity index 100%
rename from Database/Database/QueryInterfaceException.php
rename to Database/includes/QueryInterfaceException.php
diff --git a/Database/Database/ResultIterator.php 
b/Database/includes/ResultIterator.php
similarity index 100%
rename from Database/Database/ResultIterator.php
rename to Database/includes/ResultIterator.php
diff --git a/Database/Database/TableBuilder.php 
b/Database/includes/TableBuilder.php
similarity index 100%
rename from Database/Database/TableBuilder.php
rename to Database/includes/TableBuilder.php
diff --git a/Database/Database/TableCreationFailedException.php 
b/Database/includes/TableCreationFailedException.php
similarity index 100%
rename from Database/Database/TableCreationFailedException.php
rename to Database/includes/TableCreationFailedException.php
diff --git a/Database/Database/TableDefinition.php 
b/Database/includes/TableDefinition.php
similarity index 100%
rename from Database/Database/TableDefinition.php
rename to Database/includes/TableDefinition.php
diff --git a/Database/tests/phpunit/FieldDefinitionTest.php 
b/Database/tests/phpunit/FieldDefinitionTest.php
index 7e8dccb..c47d090 100644
--- a/Database/tests/phpunit/FieldDefinitionTest.php
+++ b/Database/tests/phpunit/FieldDefinitionTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use Wikibase\Database\FieldDefinition;
 
@@ -28,7 +28,6 @@
  * @ingroup WikibaseDatabaseTest
  *
  * @group Wikibase
- * @group WikibaseRepo
  * @group WikibaseDatabase
  *
  * @licence GNU GPL v2+
diff --git a/Database/tests/phpunit/MWDB/ExtendedAbstractionTest.php 
b/Database/tests/phpunit/MWDB/ExtendedAbstractionTest.php
index b8a3576..3ba4f29 100644
--- a/Database/tests/phpunit/MWDB/ExtendedAbstractionTest.php
+++ b/Database/tests/phpunit/MWDB/ExtendedAbstractionTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database\MWDB;
+namespace Wikibase\Database\Tests\MWDB;
 
 use Wikibase\Database\MWDB\ExtendedAbstraction;
 use Wikibase\Database\TableDefinition;
diff --git a/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php 
b/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
index a839ab4..c13194b 100644
--- a/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
+++ b/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
@@ -1,9 +1,9 @@
 <?php
 
-namespace Wikibase\Test\Database\MWDB;
+namespace Wikibase\Database\Tests\MWDB;
 
+use Wikibase\Database\LazyDBConnectionProvider;
 use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
-use Wikibase\Repo\LazyDBConnectionProvider;
 
 /**
  * @covers Wikibase\Database\MWDB\ExtendedMySQLAbstraction
@@ -29,7 +29,6 @@
  * @ingroup WikibaseDatabaseTest
  *
  * @group Wikibase
- * @group WikibaseRepo
  * @group WikibaseDatabase
  * @group Database
  *
diff --git a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php 
b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php
index cff6ed7..08c9520 100644
--- a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php
+++ b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php
@@ -1,13 +1,13 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use DatabaseBase;
+use Wikibase\Database\DBConnectionProvider;
 use Wikibase\Database\MediaWikiQueryInterface;
 use Wikibase\Database\QueryInterface;
 use Wikibase\Database\TableDefinition;
 use Wikibase\Database\FieldDefinition;
-use Wikibase\Repo\DBConnectionProvider;
 
 /**
  * @covers Wikibase\Database\MediaWikiQueryInterface
@@ -33,7 +33,6 @@
  * @ingroup WikibaseDatabaseTest
  *
  * @group Wikibase
- * @group WikibaseRepo
  * @group WikibaseDatabase
  *
  * @licence GNU GPL v2+
diff --git a/Database/tests/phpunit/ResultIteratorTest.php 
b/Database/tests/phpunit/ResultIteratorTest.php
index 86d2d3f..379cf7b 100644
--- a/Database/tests/phpunit/ResultIteratorTest.php
+++ b/Database/tests/phpunit/ResultIteratorTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use Wikibase\Database\ResultIterator;
 
diff --git a/Database/tests/phpunit/TableBuilderTest.php 
b/Database/tests/phpunit/TableBuilderTest.php
index b2544eb..ccf3ecb 100644
--- a/Database/tests/phpunit/TableBuilderTest.php
+++ b/Database/tests/phpunit/TableBuilderTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use Wikibase\Database\TableBuilder;
 use Wikibase\Database\FieldDefinition;
@@ -30,7 +30,6 @@
  * @ingroup WikibaseDatabaseTest
  *
  * @group Wikibase
- * @group WikibaseRepo
  * @group WikibaseDatabase
  *
  * @licence GNU GPL v2+
diff --git a/Database/tests/phpunit/TableCreationFailedExceptionTest.php 
b/Database/tests/phpunit/TableCreationFailedExceptionTest.php
index f60825f..3b6a719 100644
--- a/Database/tests/phpunit/TableCreationFailedExceptionTest.php
+++ b/Database/tests/phpunit/TableCreationFailedExceptionTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use Wikibase\Database\TableCreationFailedException;
 
diff --git a/Database/tests/phpunit/TableDefinitionTest.php 
b/Database/tests/phpunit/TableDefinitionTest.php
index 71058e6..8cb83af 100644
--- a/Database/tests/phpunit/TableDefinitionTest.php
+++ b/Database/tests/phpunit/TableDefinitionTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase\Test\Database;
+namespace Wikibase\Database\Tests;
 
 use Wikibase\Database\FieldDefinition;
 use Wikibase\Database\TableDefinition;
@@ -29,7 +29,6 @@
  * @ingroup WikibaseDatabaseTest
  *
  * @group Wikibase
- * @group WikibaseRepo
  * @group WikibaseDatabase
  *
  * @licence GNU GPL v2+
diff --git a/Database/tests/testLoader.php b/Database/tests/testLoader.php
index 5ed1f58..50f2eac 100644
--- a/Database/tests/testLoader.php
+++ b/Database/tests/testLoader.php
@@ -29,8 +29,8 @@
 
        $inTestNamespace = count( $namespaceSegments ) > 2
                && $namespaceSegments[0] === 'Wikibase'
-               && $namespaceSegments[1] === 'Test'
-               && $namespaceSegments[2] === 'Database';
+               && $namespaceSegments[1] === 'Database'
+               && $namespaceSegments[2] === 'Tests';
 
        if ( $inTestNamespace ) {
                $pathParts = explode( '/', $fileName );
diff --git a/QueryEngine/tests/phpunit/SQLStore/Engine/EngineTest.php 
b/QueryEngine/tests/phpunit/SQLStore/Engine/EngineTest.php
index acf01de..6f4b0cf 100644
--- a/QueryEngine/tests/phpunit/SQLStore/Engine/EngineTest.php
+++ b/QueryEngine/tests/phpunit/SQLStore/Engine/EngineTest.php
@@ -45,7 +45,7 @@
        protected function getInstances() {
                $instances = array();
 
-               $connectionProvider = $this->getMock( 
'Wikibase\Repo\DBConnectionProvider' );
+               $connectionProvider = $this->getMock( 
'Wikibase\Database\DBConnectionProvider' );
                $storeConfig = new StoreConfig( 'foo', 'bar', array() );
                $queryInterface = new MediaWikiQueryInterface(
                        $connectionProvider,

-- 
To view, visit https://gerrit.wikimedia.org/r/64096
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I86fdd7234a7befe4b72c5176f6e4d5462393dada
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Anja Jentzsch <[email protected]>
Gerrit-Reviewer: Ataherivand <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Lydia Pintscher <[email protected]>
Gerrit-Reviewer: Markus Kroetzsch <[email protected]>
Gerrit-Reviewer: Nikola Smolenski <[email protected]>
Gerrit-Reviewer: Silke Meyer <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to