Revert "Mechanism for renaming/aliasing classes"
authorPleaseStand <pleasestand@live.com>
Sat, 11 Jan 2014 21:48:30 +0000 (21:48 +0000)
committerPleaseStand <pleasestand@live.com>
Sat, 11 Jan 2014 21:48:30 +0000 (21:48 +0000)
Seems good in theory, though not quite usable in practice.
As with subclassing, the aliases would not work reliably
for code that uses type hints and/or instanceof.

See <https://bugs.php.net/bug.php?id=61422>, which I was
previously unaware of.

The best alternative is to add class_alias() calls to the
class files themselves, as well as duplicate entries to the
AutoLoader (just like when multiple classes are in the same
file).

There is no good way to show deprecation warnings, which
likely would have to be implemented in PHP itself. For now,
renamed classes should be indicated in RELEASE-NOTES. Maybe
I will file an RfC (at <https://wiki.php.net/rfc>) for this
and related improvements (e.g. making class names case
sensitive).

This reverts commit c61fdb4ef5dbe0c26a17e57203e0bf99aa0e2440.

Change-Id: I9771b4239543b543cfa078f357db1cd3918f081e

includes/AutoLoader.php
tests/phpunit/data/autoloader/TestAutoloadedAliasedClassNew.php [deleted file]
tests/phpunit/structure/AutoLoaderTest.php

index e6ce693..cd062e0 100644 (file)
@@ -1209,32 +1209,6 @@ class AutoLoader {
                        return;
                }
 
-               if ( substr( $filename, 0, 6 ) === 'alias:' ) {
-                       // Supported alias formats:
-                       // - No deprecation warning: alias:MyNewClassName
-                       // - Deprecated in MediaWiki 1.1: alias:MyNewClassName?v=1.1
-                       // - Deprecated in MyExtension 1.1: alias:MyNewClassName?c=MyExtension&v=1.1
-                       $parts = explode( '?', substr( $filename, 6 ), 2 );
-                       $newClassName = $parts[0];
-
-                       // If necessary, this will make a recursive call to this function to
-                       // load the class using its actual, canonical name.
-                       class_alias( $newClassName, $className );
-
-                       if ( isset( $parts[1] ) && function_exists( 'wfDeprecated' ) ) {
-                               $info = wfCgiToArray( $parts[1] );
-                               $function = "name $className for class $newClassName";
-                               $version = isset( $info['v'] ) ? $info['v'] : false;
-                               $component = isset( $info['c'] ) ? $info['c'] : false;
-
-                               // https://github.com/facebook/hhvm/issues/1018
-                               $callerOffset = wfIsHHVM() ? 2 : 3;
-                               wfDeprecated( $function, $version, $component, $callerOffset );
-                       }
-
-                       return;
-               }
-
                # Make an absolute path, this improves performance by avoiding some stat calls
                if ( substr( $filename, 0, 1 ) != '/' && substr( $filename, 1, 1 ) != ':' ) {
                        global $IP;
diff --git a/tests/phpunit/data/autoloader/TestAutoloadedAliasedClassNew.php b/tests/phpunit/data/autoloader/TestAutoloadedAliasedClassNew.php
deleted file mode 100644 (file)
index 5ce8483..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
-
-class TestAutoloadedAliasedClassNew {
-}
index 1ffe811..d8b90d5 100644 (file)
@@ -11,9 +11,6 @@ class AutoLoaderTest extends MediaWikiTestCase {
                        'TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
                        'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
                        'TestAutoloadedSerializedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
-                       'TestAutoloadedAliasedClass' => 'alias:TestAutoloadedAliasedClassNew',
-                       'TestAutoloadedAliasedClassDeprecated' => 'alias:TestAutoloadedAliasedClassNew?v=1.1',
-                       'TestAutoloadedAliasedClassNew' => __DIR__ . '/../data/autoloader/TestAutoloadedAliasedClassNew.php',
                );
                $this->setMwGlobals( 'wgAutoloadLocalClasses', $this->testLocalClasses + $wgAutoloadLocalClasses );
                AutoLoader::resetAutoloadLocalClassesLower();
@@ -47,23 +44,7 @@ class AutoLoaderTest extends MediaWikiTestCase {
                $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses;
                $actual = array();
 
-               // Check aliases
-               foreach ( $expected as $class => $file ) {
-                       if ( substr( $file, 0, 6 ) !== 'alias:' ) {
-                               // Not an alias, so should be an actual file
-                               $files[] = $file;
-                       } else {
-                               $newClass = substr( $file, 6, strcspn( $file, '?', 6 ) );
-                               if ( isset( $expected[$newClass] ) ) {
-                                       if ( substr( $expected[$newClass], 0, 6 ) !== 'alias:' ) {
-                                               // Alias pointing to an existing MediaWiki class
-                                               $actual[$class] = $file;
-                                       }
-                               }
-                       }
-               }
-
-               $files = array_unique( $files );
+               $files = array_unique( $expected );
 
                foreach ( $files as $file ) {
                        // Only prefix $IP if it doesn't have it already.
@@ -111,16 +92,4 @@ class AutoLoaderTest extends MediaWikiTestCase {
                $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
                        "unserialize() can load classes case-insensitively." );
        }
-
-       function testAliasedClass() {
-               $this->assertSame( 'TestAutoloadedAliasedClassNew',
-                       get_class( new TestAutoloadedAliasedClass ) );
-       }
-
-       function testAliasedClassDeprecated() {
-               wfSuppressWarnings();
-               $this->assertSame( 'TestAutoloadedAliasedClassNew',
-                       get_class( new TestAutoloadedAliasedClassDeprecated ) );
-               wfRestoreWarnings();
-       }
 }