Skip to content

Commit

Permalink
Merge pull request #2507 from codeigniter4/searchorder
Browse files Browse the repository at this point in the history
Update ordering of search locations for better prioritization. Fixes #2354
  • Loading branch information
lonnieezell authored Jan 23, 2020
2 parents 0eedc0e + 2c7aa2c commit fc195f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand Down
15 changes: 15 additions & 0 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,32 @@ 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,
];
}
}

$namespaces[] = $system;

return $namespaces;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -170,7 +170,6 @@ public function testSearchWithMultipleFilesFound()
$this->assertContains($expected, $foundFiles);

$expected = SYSTEMPATH . 'index.html';

$this->assertContains($expected, $foundFiles);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down

0 comments on commit fc195f7

Please sign in to comment.