Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/72460
Change subject: Add PSR-0 based class loading ...................................................................... Add PSR-0 based class loading Change-Id: Id0ed94b053327b37f2abef5fec0b7f308e069466 --- D ParserHooks.classes.php M ParserHooks.php 2 files changed, 23 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ParserHooks refs/changes/60/72460/1 diff --git a/ParserHooks.classes.php b/ParserHooks.classes.php deleted file mode 100644 index 53a1be8..0000000 --- a/ParserHooks.classes.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -/** - * Class registration file for the ParserHooks MediaWiki extension. - * - * @since 0.1 - * - * @file - * @ingroup ParserHooks - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -return array( - - 'ParserHooks\FunctionRunner' => 'includes/FunctionRunner.php', - 'ParserHooks\HookDefinition' => 'includes/HookDefinition.php', - 'ParserHooks\HookHandler' => 'includes/HookHandler.php', - 'ParserHooks\HookRegistrant' => 'includes/HookRegistrant.php', - -); diff --git a/ParserHooks.php b/ParserHooks.php index 4c7eb93..e8a0d0b 100644 --- a/ParserHooks.php +++ b/ParserHooks.php @@ -31,9 +31,31 @@ define( 'ParserHooks_VERSION', '0.1 alpha' ); // @codeCoverageIgnoreStart +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] === 'ParserHooks' ) { + if ( count( $namespaceSegments ) === 1 || $namespaceSegments[1] !== 'Tests' ) { + require_once __DIR__ . '/includes/' . $fileName; + } + } +} ); + call_user_func( function() { - global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgAutoloadClasses, $wgHooks; + global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; $wgExtensionCredits['other'][] = array( 'path' => __FILE__, @@ -47,12 +69,6 @@ ); $wgExtensionMessagesFiles['ParserHooksExtension'] = __DIR__ . '/ParserHooks.i18n.php'; - - foreach ( include( __DIR__ . '/ParserHooks.classes.php' ) as $class => $file ) { - if ( !array_key_exists( $class, $GLOBALS['wgAutoloadLocalClasses'] ) ) { - $wgAutoloadClasses[$class] = __DIR__ . '/' . $file; - } - } /** * Hook to add PHPUnit test cases. -- To view, visit https://gerrit.wikimedia.org/r/72460 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id0ed94b053327b37f2abef5fec0b7f308e069466 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ParserHooks Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
