Skip to content

Commit

Permalink
Remove unnecessary logic from autoloaders locate function
Browse files Browse the repository at this point in the history
The autoloader can only locate classes and will never attempt
to locate them twice so the caching was not needed.

This is part of MON-9182

Signed-off-by: Tobias Sjöndin <tsjondin@op5.com>
  • Loading branch information
Tobias Sjöndin committed Mar 9, 2016
1 parent eb96071 commit a6edce0
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,33 @@
call_user_func(function () {

$root = dirname(__FILE__);
$include_paths = array();

/**
* Set include paths for all modules that we have
*/
foreach (glob($root . '/modules/*', GLOB_ONLYDIR) as $path) {
$include_paths[] = $path;
}

$include_paths = glob($root . '/modules/*', GLOB_ONLYDIR);
$include_paths[] = $root . '/application';
$include_paths[] = $root . '/system';

/**
* This is a "copy" of the Kohana::find_file that does not depend on
* any global constants being set
* This function locates classes as Kohanas find_file does it
* but can ignore caching since a class will never be located
* twice once included, and ignore config files and more since
* this can only load classes.
*/
$file_cache = array();
$locate = function ($directory, $filename) use (&$file_cache, &$include_paths) {

$search = $directory.'/'.$filename.'.php';
if (isset($file_cache[$search])) return $file_cache[$search];
$locate = function ($directory, $filename) use ($include_paths) {

$paths = $include_paths;
$found = NULL;
$file = false;
$classpath = $directory.'/'.$filename.'.php';

if ($directory === 'config' OR $directory === 'i18n' OR $directory === 'config/custom') {
$paths = array_reverse($paths);
foreach ($paths as $path) {
if (is_file($path.'/'.$search)) {
$found[] = $path.'/'.$search;
}
}
} else {
foreach ($paths as $path) {
if (is_file($path.'/'.$search)) {
$found = $path.'/'.$search;
break;
}
foreach ($include_paths as $path) {
if (is_file($path.'/'.$classpath)) {
$file = $path.'/'.$classpath;
break;
}
}

if ($found === NULL) $found = false;
return $file_cache[$search] = $found;
return $file;

};

Expand Down

0 comments on commit a6edce0

Please sign in to comment.