MDL-43365 lib: converted text and plugin deprecated classes to new scheme
authorSam Hemelryk <sam@moodle.com>
Tue, 24 Jun 2014 21:30:35 +0000 (09:30 +1200)
committerSam Hemelryk <sam@moodle.com>
Tue, 24 Jun 2014 21:30:38 +0000 (09:30 +1200)
Four core library classes renamed for autoloading with deprecated stubs
have been converted to the new scheme for autoloading.
They are:

 * textlib
 * collatorlib
 * plugin_manager
 * plugininfo_base

These will be removed in 2.9 by MDL-46124

lib/accesslib.php
lib/classes/collator.php
lib/classes/text.php
lib/db/renamedclasses.php [new file with mode: 0644]
lib/pluginlib.php
lib/tests/collator_test.php
lib/tests/text_test.php
question/format/webct/format.php

index 147da15..7e8beca 100644 (file)
@@ -2988,7 +2988,7 @@ function get_component_string($component, $contextlevel) {
 
     if ($component === 'moodle' or $component === 'core') {
         switch ($contextlevel) {
-            // TODO: this should probably use context level names instead
+            // TODO MDL-46123: this should probably use context level names instead
             case CONTEXT_SYSTEM:    return get_string('coresystem');
             case CONTEXT_USER:      return get_string('users');
             case CONTEXT_COURSECAT: return get_string('categories');
@@ -3007,7 +3007,7 @@ function get_component_string($component, $contextlevel) {
     }
 
     switch ($type) {
-        // TODO: this is really hacky, anyway it should be probably moved to lib/pluginlib.php
+        // TODO MDL-46123: this is really hacky and should be improved.
         case 'quiz':         return get_string($name.':componentname', $component);// insane hack!!!
         case 'repository':   return get_string('repository', 'repository').': '.get_string('pluginname', $component);
         case 'gradeimport':  return get_string('gradeimport', 'grades').': '.get_string('pluginname', $component);
index 7f5f216..ad779f2 100644 (file)
@@ -307,10 +307,3 @@ class core_collator {
         return true;
     }
 }
-
-/**
- * Legacy collatorlib.
- * @deprecated since 2.6, use core_collator:: instead.
- */
-class collatorlib extends core_collator {
-}
index 0cba907..8e730cb 100644 (file)
@@ -695,22 +695,4 @@ class core_text {
         }
         return implode(' ', $words);
     }
-}
-
-/**
- * Legacy tectlib.
- * @deprecated since 2.6, use core_text:: instead.
- */
-class textlib extends core_text {
-    /**
-     * Locale aware sorting, the key associations are kept, values are sorted alphabetically.
-     *
-     * @param array $arr array to be sorted (reference)
-     * @param int $sortflag One of Collator::SORT_REGULAR, Collator::SORT_NUMERIC, Collator::SORT_STRING
-     * @return void modifies parameter
-     */
-    public static function asort(array &$arr, $sortflag = null) {
-        debugging('textlib::asort has been superseeded by collatorlib::asort please upgrade your code to use that', DEBUG_DEVELOPER);
-        collatorlib::asort($arr, $sortflag);
-    }
 }
\ No newline at end of file
diff --git a/lib/db/renamedclasses.php b/lib/db/renamedclasses.php
new file mode 100644 (file)
index 0000000..141cdfe
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle 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 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader.
+ *
+ * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a
+ * close structure, OR where lots of classes get included and not necessarily used, or checked for often.
+ *
+ * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that
+ * component.
+ * This way we don't need to keep around old classes, instead creating aliases only when required.
+ * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used.
+ *
+ * @package    core
+ * @copyright  2014 Sam Hemelryk
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Like other files in the db directory this file uses an array.
+// The old class name is the key, the new class name is the value.
+// The array must be called $renamedclasses.
+$renamedclasses = array(
+
+    // Deprecated in 2.6.
+    // TODO MDL-46124: Remove textlib. collatorlib, plugin_manager, and plugininfo base in 2.9.
+    'textlib' => 'core_text',
+    'collatorlib' => 'core_collator',
+    'plugin_manager' => 'core_plugin_manager',
+    'plugininfo_base' => 'core\plugininfo\base'
+
+);
index 6716a06..4cf3de6 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -22,6 +21,7 @@
  * Moodle. It is mainly used by the plugins management admin page and the
  * plugins check page during the upgrade.
  *
+ * @todo MDL-46122 This file will be removed in 2.9
  * @package    core
  * @copyright  2011 David Mudrak <david@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 
 defined('MOODLE_INTERNAL') || die();
 
-
-/**
- * @deprecated since 2.6 - use core_plugin_manager instead.
- */
-class plugin_manager extends core_plugin_manager {
-    // BC only.
-    public static function instance() {
-        return core_plugin_manager::instance();
-    }
-}
-
-/**
- * @deprecated since 2.6 - use \core\plugininfo\base instead.
- */
-class plugininfo_base extends \core\plugininfo\base {
-    // BC only.
-}
-
+debugging('lib/pluginlib.php has been deprecated, the classes that used to exist are now autoloaded. Please removed ' .
+          'any calls to include or require this file.', DEBUG_DEVELOPER);
\ No newline at end of file
index a523da3..5711157 100644 (file)
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2011 Sam Hemelryk
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class core_collator_testcase extends basic_testcase {
+class core_collator_testcase extends advanced_testcase {
 
     /**
      * @var string The initial lang, stored because we change it during testing
@@ -244,6 +244,7 @@ class core_collator_testcase extends basic_testcase {
     public function test_legacy_collatorlib() {
         $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
         $result = collatorlib::asort($arr);
+        $this->assertDebuggingCalled(null, null, 'This fails if any other test uses the deprecated collatorlib class.');
         $this->assertSame(array('aa', 'ab', 'cc'), array_values($arr));
         $this->assertSame(array(1, 'b', 0), array_keys($arr));
         $this->assertTrue($result);
index 9e6aca8..460c5c9 100644 (file)
@@ -350,6 +350,7 @@ class core_text_testcase extends advanced_testcase {
 
     public function test_deprecated_textlib() {
         $this->assertSame(textlib::strtolower('HUH'), core_text::strtolower('HUH'));
+        $this->assertDebuggingCalled(null, null, 'This fails if any other test uses the deprecated textlib class.');
     }
 
     /**
index 5c45f1d..4e184bc 100644 (file)
@@ -351,7 +351,7 @@ class qformat_webct extends qformat_default {
 
         foreach ($lines as $line) {
             $nlinecounter++;
-            $line = textlib::convert($line, 'windows-1252', 'utf-8');
+            $line = core_text::convert($line, 'windows-1252', 'utf-8');
             // Processing multiples lines strings.
 
             if (isset($questiontext) and is_string($questiontext)) {