From 2c7aa2c8c10be115b79cbbbfb3b46c28e48ee647 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Wed, 22 Jan 2020 23:38:22 -0600 Subject: [PATCH] Update ordering of search locations for better prioritization. Fixes #2354 --- app/Config/Autoload.php | 4 ++-- system/Autoloader/FileLocator.php | 15 +++++++++++++++ tests/system/Autoloader/FileLocatorTest.php | 3 +-- tests/system/Language/LanguageTest.php | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index af0e2018fb73..6a673d31ebbf 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -50,9 +50,9 @@ public function __construct() * `]; */ $psr4 = [ - 'Config' => APPPATH . 'Config', - APP_NAMESPACE => APPPATH, // For custom namespace 'App' => APPPATH, // To ensure filters, etc still found, + APP_NAMESPACE => APPPATH, // For custom namespace + 'Config' => APPPATH . 'Config', ]; /** diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 7d3818b21325..dac511a1c2c0 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -287,10 +287,23 @@ protected function getNamespaces() { $namespaces = []; + // Save system for last + $system = null; + foreach ($this->autoloader->getNamespace() as $prefix => $paths) { foreach ($paths as $path) { + if ($prefix === 'CodeIgniter') + { + $system = [ + 'prefix' => $prefix, + 'path' => rtrim($path, '\\/') . DIRECTORY_SEPARATOR, + ]; + + continue; + } + $namespaces[] = [ 'prefix' => $prefix, 'path' => rtrim($path, '\\/') . DIRECTORY_SEPARATOR, @@ -298,6 +311,8 @@ protected function getNamespaces() } } + $namespaces[] = $system; + return $namespaces; } diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index aae6927b6261..abacc37f5eae 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -22,8 +22,8 @@ protected function setUp(): void 'Tests/Support' => TESTPATH . '_support/', 'App' => APPPATH, 'CodeIgniter' => [ - SYSTEMPATH, TESTPATH, + SYSTEMPATH, ], 'Errors' => APPPATH . 'Views/errors', 'System' => SUPPORTPATH . 'Autoloader/system', @@ -170,7 +170,6 @@ public function testSearchWithMultipleFilesFound() $this->assertContains($expected, $foundFiles); $expected = SYSTEMPATH . 'index.html'; - $this->assertContains($expected, $foundFiles); } diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 2f1f94634cf8..dabe704bdd91 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -221,7 +221,7 @@ public function testPrioritizedLocator() $language = Services::language('en', false); // this should load the replacement bundle of messages $message = lang('Core.missingExtension', [], 'en'); - $this->assertEquals('{0} extension could not be found.', $message); + $this->assertEquals('{0} extension is not loaded.', $message); // and we should have our new message too $this->assertEquals('billions and billions', lang('Core.bazillion', [], 'en')); }