Skip to content

Instantly share code, notes, and snippets.

@rajeshtaneja
Created June 19, 2015 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeshtaneja/7f004d1f3250891efed2 to your computer and use it in GitHub Desktop.
Save rajeshtaneja/7f004d1f3250891efed2 to your computer and use it in GitHub Desktop.
Move known classes to autoloading
diff --git a/lib/classes/component.php b/lib/classes/component.php
index 95f9044..402aa12 100644
--- a/lib/classes/component.php
+++ b/lib/classes/component.php
@@ -69,6 +69,14 @@ class core_component {
protected static $filestomap = array('lib.php', 'settings.php');
/** @var array cache of PSR loadable systems */
protected static $psrclassmap = null;
+ /** @var array list of known classes. */
+ protected static $knownclasses = array(
+ 'file_browser' => '/lib/filebrowser/file_browser.php',
+ 'file_info' => '/lib/filebrowser/file_info.php',
+ 'file_info_stored' => '/lib/filebrowser/file_info_stored.php',
+ 'file_storage' => '/lib/filestorage/file_storage.php',
+ 'zip_packer' => '/lib/filestorage/zip_packer.php',
+ );
/**
* Class loader for Frankenstyle named classes in standard locations.
@@ -87,6 +95,7 @@ class core_component {
* @param string $classname
*/
public static function classloader($classname) {
+ global $CFG;
self::init();
if (isset(self::$classmap[$classname])) {
@@ -114,6 +123,11 @@ class core_component {
include_once(self::$psrclassmap[$normalizedclassname]);
return;
}
+
+ // Check if it's a known class path
+ if (isset(self::$knownclasses[$classname])) {
+ include_once($CFG->dirroot . self::$knownclasses[$classname]);
+ }
}
/**
diff --git a/lib/filelib.php b/lib/filelib.php
index 185bcd6..e5c43b2 100644
--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -35,9 +35,9 @@ define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7');
define('FILE_AREA_MAX_BYTES_UNLIMITED', -1);
require_once("$CFG->libdir/filestorage/file_exceptions.php");
-require_once("$CFG->libdir/filestorage/file_storage.php");
+/*require_once("$CFG->libdir/filestorage/file_storage.php");
require_once("$CFG->libdir/filestorage/zip_packer.php");
-require_once("$CFG->libdir/filebrowser/file_browser.php");
+require_once("$CFG->libdir/filebrowser/file_browser.php");*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment