Skip to content

Commit 638a5d7

Browse files
authored
Merge pull request #4756 from samsonasik/include_once_not_needed_on_config_no_namespace
[Autoloader] include_once is not needed on Autoloader::loadClass() with no namespace
2 parents 5fc58f9 + 81c5454 commit 638a5d7

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

system/Autoloader/Autoloader.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
* An autoloader that uses both PSR4 autoloading, and traditional classmaps.
2323
*
2424
* Given a foo-bar package of classes in the file system at the following paths:
25-
*```
25+
* ```
2626
* /path/to/packages/foo-bar/
2727
* /src
2828
* Baz.php # Foo\Bar\Baz
2929
* Qux/
3030
* Quux.php # Foo\Bar\Qux\Quux
31-
*```
31+
* ```
3232
* you can add the path to the configuration array that is passed in the constructor.
3333
* The Config array consists of 2 primary keys, both of which are associative arrays:
3434
* 'psr4', and 'classmap'.
35-
*```
35+
* ```
3636
* $Config = [
3737
* 'psr4' => [
3838
* 'Foo\Bar' => '/path/to/packages/foo-bar'
@@ -41,17 +41,17 @@
4141
* 'MyClass' => '/path/to/class/file.php'
4242
* ]
4343
* ];
44-
*```
44+
* ```
4545
* Example:
46-
*```
46+
* ```
4747
* <?php
4848
* // our configuration array
4949
* $Config = [ ... ];
5050
* $loader = new \CodeIgniter\Autoloader\Autoloader($Config);
5151
*
5252
* // register the autoloader
5353
* $loader->register();
54-
*```
54+
* ```
5555
*/
5656
class Autoloader
5757
{
@@ -258,15 +258,6 @@ protected function loadInNamespace(string $class)
258258
{
259259
if (strpos($class, '\\') === false)
260260
{
261-
$class = 'Config\\' . $class;
262-
$filePath = APPPATH . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
263-
$filename = $this->includeFile($filePath);
264-
265-
if ($filename)
266-
{
267-
return $filename;
268-
}
269-
270261
return false;
271262
}
272263

@@ -353,7 +344,9 @@ protected function discoverComposerNamespaces()
353344
return;
354345
}
355346

356-
/** @var ClassLoader $composer */
347+
/**
348+
* @var ClassLoader $composer
349+
*/
357350
$composer = include COMPOSER_PATH;
358351
$paths = $composer->getPrefixesPsr4();
359352
$classes = $composer->getClassMap();

tests/system/Autoloader/AutoloaderTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,9 @@ public function testRemoveNamespace()
172172
$this->assertFalse((bool) $this->loader->loadClass('My\App\AutoloaderTest'));
173173
}
174174

175-
public function testloadClassConfigFound()
175+
public function testloadClassNonNamespaced()
176176
{
177-
$this->loader->addNamespace('Config', APPPATH . 'Config');
178-
$this->assertSame(
179-
APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Modules.php',
180-
$this->loader->loadClass('Modules')
181-
);
182-
}
183-
184-
public function testloadClassConfigNotFound()
185-
{
186-
$this->loader->addNamespace('Config', APPPATH . 'Config');
187-
$this->assertFalse($this->loader->loadClass('NotFound'));
177+
$this->assertFalse($this->loader->loadClass('Modules'));
188178
}
189179

190180
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)