Skip to content

Commit

Permalink
Merge pull request codeigniter4#8553 from ddevsr/perf-load-namespace
Browse files Browse the repository at this point in the history
refactor: small improvement in `loadInNamespace` Autoloader
  • Loading branch information
kenjis authored Feb 21, 2024
2 parents fcd8597 + 73e7503 commit cc9ce52
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ protected function loadInNamespace(string $class)
}

foreach ($this->prefixes as $namespace => $directories) {
foreach ($directories as $directory) {
$directory = rtrim($directory, '\\/');
if (strpos($class, $namespace) === 0) {
$relativeClassPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace)));

if (strpos($class, $namespace) === 0) {
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
foreach ($directories as $directory) {
$directory = rtrim($directory, '\\/');

$filePath = $directory . $relativeClassPath . '.php';
$filename = $this->includeFile($filePath);

if ($filename) {
Expand Down

0 comments on commit cc9ce52

Please sign in to comment.