Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/63151


Change subject: Got rid of autoload registration since we can auto resolve the 
paths
......................................................................

Got rid of autoload registration since we can auto resolve the paths

Change-Id: Idd79e11fe1ab66ed62577504a62a6f30b7eed89f
---
D Ask.classes.php
M Ask.mw.php
M Ask.php
D Ask.standalone.php
D Tests/AskTestClasses.php
M Tests/bootstrap.php
A Tests/testLoader.php
7 files changed, 68 insertions(+), 154 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Ask 
refs/changes/51/63151/1

diff --git a/Ask.classes.php b/Ask.classes.php
deleted file mode 100644
index f3925a8..0000000
--- a/Ask.classes.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-
-/**
- * Class registration file for the Ask library.
- *
- * @since 0.1
- *
- * @file
- * @ingroup Ask
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-return call_user_func( function() {
-
-       // PSR-0 compliant :)
-
-       $classes = array(
-               'Ask\Arrayable',
-               'Ask\ArrayValueProvider',
-               'Ask\Comparable',
-               'Ask\Hashable',
-               'Ask\Immutable',
-               'Ask\Typeable',
-
-               'Ask\Language\Description\AnyValue',
-               'Ask\Language\Description\Conjunction',
-               'Ask\Language\Description\Description',
-               'Ask\Language\Description\DescriptionCollection',
-               'Ask\Language\Description\Disjunction',
-               'Ask\Language\Description\SomeProperty',
-               'Ask\Language\Description\ValueDescription',
-
-               'Ask\Language\Option\PropertyValueSortExpression',
-               'Ask\Language\Option\QueryOptions',
-               'Ask\Language\Option\SortExpression',
-               'Ask\Language\Option\SortOptions',
-
-
-               'Ask\Language\Selection\PropertySelection',
-               'Ask\Language\Selection\SelectionRequest',
-               'Ask\Language\Selection\SubjectSelection',
-
-               'Ask\Language\Query'
-       );
-
-       $paths = array();
-
-       foreach ( $classes as $class ) {
-               $path = 'includes/' . str_replace( '\\', '/', $class ) . '.php';
-
-               $paths[$class] = $path;
-       }
-
-       return $paths;
-
-} );
diff --git a/Ask.mw.php b/Ask.mw.php
index 90ce676..f1093d7 100644
--- a/Ask.mw.php
+++ b/Ask.mw.php
@@ -28,6 +28,8 @@
  * @author Jeroen De Dauw < [email protected] >
  */
 
+// @codeCoverageIgnoreStart
+
 if ( !defined( 'MEDIAWIKI' ) ) {
        die( 'Not an entry point.' );
 }
@@ -38,15 +40,8 @@
 
 $wgExtensionMessagesFiles['AskExtension'] = __DIR__ . '/Ask.i18n.php';
 
-// Autoloading
-foreach ( include( __DIR__ . '/Ask.classes.php' ) as $class => $file ) {
-       $wgAutoloadClasses[$class] = __DIR__ . '/' . $file;
-}
-
 if ( defined( 'MW_PHPUNIT_TEST' ) ) {
-       foreach ( include( __DIR__ . '/Tests/AskTestClasses.php' ) as $class => 
$file ) {
-               $wgAutoloadClasses[$class] = __DIR__ . '/../' . $file;
-       }
+       require_once __DIR__ . '/Tests/testLoader.php';
 }
 
 /**
@@ -62,7 +57,7 @@
  * @return boolean
  */
 $wgHooks['UnitTestsList'][]    = function( array &$files ) {
-       // @codeCoverageIgnoreStart
+
        $testFiles = array(
                'Language/Description/AnyValue',
                'Language/Description/Conjunction',
@@ -85,5 +80,6 @@
        }
 
        return true;
-       // @codeCoverageIgnoreEnd
 };
+
+// @codeCoverageIgnoreEnd
diff --git a/Ask.php b/Ask.php
index 4b70526..00b7561 100644
--- a/Ask.php
+++ b/Ask.php
@@ -41,8 +41,31 @@
 define( 'Ask_VERSION', '0.1 alpha' );
 
 // @codeCoverageIgnoreStart
-call_user_func( function() {
-       $extension = defined( 'MEDIAWIKI' ) ? 'mw' : 'standalone';
-       require_once __DIR__ . '/Ask.' . $extension . '.php';
+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 );
+
+       if ( $namespaceSegments[0] === 'Ask' ) {
+               if ( count( $namespaceSegments ) === 1 || $namespaceSegments[1] 
!== 'Tests' ) {
+                       require_once __DIR__ . '/includes/' . $fileName;
+               }
+       }
 } );
-// @codeCoverageIgnoreEnd
+
+call_user_func( function() {
+       if ( defined( 'MEDIAWIKI' ) ) {
+               require_once __DIR__ . '/Ask.mw.php';
+       }
+} );
+// @codeCoverageIgnoreEnd
\ No newline at end of file
diff --git a/Ask.standalone.php b/Ask.standalone.php
deleted file mode 100644
index 978cc4d..0000000
--- a/Ask.standalone.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-/**
- * Standalone setup for the Ask library for when it's not used in conjunction 
with MediaWiki.
- * The library should be included via the main entry point, Ask.php.
- *
- * Documentation:                      
https://www.mediawiki.org/wiki/Extension:Ask
- * Support                                     
https://www.mediawiki.org/wiki/Extension_talk:Ask
- * Source code:                                
https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/Ask.git
- *
- * @file
- * @ingroup Ask
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-
-if ( defined( 'MEDIAWIKI' ) ) {
-       die( 'Not an entry point for MediaWiki. Use Ask.php' );
-}
-
-spl_autoload_register( function ( $className ) {
-       static $classes = false;
-
-       if ( $classes === false ) {
-               $classes = include( __DIR__ . '/' . 'Ask.classes.php' );
-       }
-
-       if ( array_key_exists( $className, $classes ) ) {
-               include_once __DIR__ . '/' . $classes[$className];
-       }
-} );
diff --git a/Tests/AskTestClasses.php b/Tests/AskTestClasses.php
deleted file mode 100644
index fb52243..0000000
--- a/Tests/AskTestClasses.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-/**
- * Test class registration file for the Ask library.
- *
- * @since 0.1
- *
- * @file
- * @ingroup Ask
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-return call_user_func( function() {
-
-       // PSR-0 compliant :)
-
-       $classes = array(
-               'Ask\Tests\Phpunit\AskTestCase',
-
-               'Ask\Tests\Phpunit\Language\Description\DescriptionTest',
-               
'Ask\Tests\Phpunit\Language\Description\DescriptionCollectionTest',
-
-               'Ask\Tests\Phpunit\Language\Option\SortExpressionTest',
-
-               'Ask\Tests\Phpunit\Language\Selection\SelectionRequestTest',
-       );
-
-       $paths = array();
-
-       foreach ( $classes as $class ) {
-               $path = str_replace( '\\', '/', $class ) . '.php';
-
-               $paths[$class] = $path;
-       }
-
-       return $paths;
-
-} );
diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php
index 95507fd..274a408 100644
--- a/Tests/bootstrap.php
+++ b/Tests/bootstrap.php
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Test class registration file for the Ask library.
+ * PHPUnit test bootstrap file for the Ask library.
  *
  * @since 0.1
  *
@@ -14,14 +14,4 @@
 
 require_once( __DIR__ . '/../Ask.php' );
 
-spl_autoload_register( function ( $className ) {
-       static $classes = false;
-
-       if ( $classes === false ) {
-               $classes = include(  __DIR__ . '/AskTestClasses.php' );
-       }
-
-       if ( array_key_exists( $className, $classes ) ) {
-               include_once __DIR__ . '/../../' . $classes[$className];
-       }
-} );
\ No newline at end of file
+require_once( __DIR__ . '/testLoader.php' );
diff --git a/Tests/testLoader.php b/Tests/testLoader.php
new file mode 100644
index 0000000..f2405d2
--- /dev/null
+++ b/Tests/testLoader.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * Test class autoloader for the Ask library.
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup Ask
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+
+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 );
+
+       if ( count( $namespaceSegments ) > 1 && $namespaceSegments[0] === 'Ask' 
&& $namespaceSegments[1] === 'Tests' ) {
+               require_once __DIR__ . '/../../' . $fileName;
+       }
+} );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd79e11fe1ab66ed62577504a62a6f30b7eed89f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

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

Reply via email to