Permalink
Browse files

fix(autoload): fixes bugs in class map saving

The autoloader class map now marks itself altered only if a path is changed or
set initially. This allows `elgg_register_class()` to be called on every request
without triggering a re-save.

In 1.12, the `engine/lib` loader now properly calls the setup function returned
by `autoload.php`, allowing the class map to be saved. This bug does not exist
in 2.x.

Refs #9744
  • Loading branch information...
mrclay committed Apr 20, 2016
1 parent 3af74ad commit 18ea55fa990fab9724cbbd12365d754df19cbde2
Showing with 7 additions and 4 deletions.
  1. +4 −2 engine/classes/Elgg/ClassMap.php
  2. +3 −2 engine/load.php
@@ -44,8 +44,10 @@ public function setPath($class, $path) {
if ('\\' === $class[0]) {
$class = substr($class, 1);
}
$this->map[$class] = $path;
$this->altered = true;
if (!isset($this->map[$class]) || $this->map[$class] !== $path) {
$this->map[$class] = $path;
$this->altered = true;
}
return $this;
}
View
@@ -8,7 +8,7 @@
$lib_dir = __DIR__ . "/lib";
require_once "$lib_dir/autoloader.php";
$autoloader_setup = (require_once "$lib_dir/autoloader.php");
$autoload_path = dirname(__DIR__) . '/vendor/autoload.php';
$autoload_available = include_once($autoload_path);
@@ -79,7 +79,7 @@
);
// isolate global scope
call_user_func(function () use ($lib_dir, $lib_files) {
call_user_func(function () use ($lib_dir, $lib_files, $autoloader_setup) {
$setups = array();
@@ -96,6 +96,7 @@
$hooks = _elgg_services()->hooks;
// run setups
$autoloader_setup($events, $hooks);
foreach ($setups as $func) {
$func($events, $hooks);
}

0 comments on commit 18ea55f

Please sign in to comment.