Skip to content

Commit 87085d2

Browse files
committed
refactor(autoload): Renamed AutoLoader to ClassLoader
1 parent 58d58e2 commit 87085d2

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

bootstrap.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
use webfiori\framework\App;
7-
use webfiori\framework\autoload\AutoLoader;
7+
use webfiori\framework\autoload\ClassLoader;
88

99
$DS = DIRECTORY_SEPARATOR;
1010

@@ -23,15 +23,15 @@
2323
fprintf(STDOUT, "Bootstrap Path: '".__DIR__."'\n");
2424
fprintf(STDOUT,"Tests Directory: '".TESTS_DIRECTORY."'.\n");
2525
fprintf(STDOUT,'Include Path: \''.get_include_path().'\''."\n");
26-
fprintf(STDOUT,"Tryning to load the class 'AutoLoader'...\n");
26+
fprintf(STDOUT,"Tryning to load the class 'ClassLoader'...\n");
2727
$isAutoloaderLoaded = false;
2828

2929
if (explode($DS, __DIR__)[0] == 'home') {
3030
fprintf(STDOUT,"Run Environment: Linux.\n");
3131

3232
foreach ($WebFioriFrameworkDirs as $dir) {
3333
//linux
34-
$file = $DS.$dir.'framework'.$DS.'autoload'.$DS.'AutoLoader.php';
34+
$file = $DS.$dir.'framework'.$DS.'autoload'.$DS.'ClassLoader.php';
3535
fprintf(STDOUT,"Checking if file '$file' is exist...\n");
3636

3737
if (file_exists($file)) {
@@ -45,7 +45,7 @@
4545

4646
foreach ($WebFioriFrameworkDirs as $dir) {
4747
//other
48-
$file = $dir.$DS.'framework'.$DS.'autoload'.$DS.'AutoLoader.php';
48+
$file = $dir.$DS.'framework'.$DS.'autoload'.$DS.'ClassLoader.php';
4949
fprintf(STDOUT,"Checking if file '$file' is exist...\n");
5050

5151
if (file_exists($file)) {
@@ -57,13 +57,13 @@
5757
}
5858

5959
if ($isAutoloaderLoaded === false) {
60-
fprintf(STDERR, "Error: Unable to find the class 'AutoLoader'.\n");
60+
fprintf(STDERR, "Error: Unable to find the class 'ClassLoader'.\n");
6161
exit(-1);
6262
} else {
63-
fprintf(STDOUT,"Class 'AutoLoader' successfully loaded.\n");
63+
fprintf(STDOUT,"Class 'ClassLoader' successfully loaded.\n");
6464
}
6565
fprintf(STDOUT,"Initializing autoload directories...\n");
66-
AutoLoader::get([
66+
ClassLoader::get([
6767
'search-folders' => [
6868
'tests',
6969
'webfiori',
@@ -79,8 +79,8 @@
7979
fprintf(STDOUT,"Initializing application...\n");
8080
App::start();
8181
fprintf(STDOUT,'Done.'."\n");
82-
fprintf(STDOUT,'Root Directory: \''.AutoLoader::get()->root().'\'.'."\n");
83-
define('TESTS_PATH', AutoLoader::get()->root().$DS.TESTS_DIRECTORY);
82+
fprintf(STDOUT,'Root Directory: \''.ClassLoader::get()->root().'\'.'."\n");
83+
define('TESTS_PATH', ClassLoader::get()->root().$DS.TESTS_DIRECTORY);
8484
fprintf(STDOUT,'Tests Path: '.TESTS_PATH."\n");
8585
fprintf(STDOUT,'App Path: '.APP_PATH."\n");
8686
fprintf(STDOUT,"---------------------------------\n");

tests/webfiori/framework/test/TestAutoLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace webfiori\framework\test;
33

44
use PHPUnit\Framework\TestCase;
5-
use webfiori\framework\autoload\AutoLoader;
5+
use webfiori\framework\autoload\ClassLoader;
66
/**
77
* Description of TestAutoLoader
88
*
@@ -13,24 +13,24 @@ class TestAutoLoader extends TestCase {
1313
* @test
1414
*/
1515
public function test00() {
16-
$this->assertEquals(ROOT_PATH, AutoLoader::root());
16+
$this->assertEquals(ROOT_PATH, ClassLoader::root());
1717
}
1818
/**
1919
* @test
2020
*/
2121
public function test01() {
22-
$cArr = explode('\\', 'webfiori\\framework\\autoload\\AutoLoader');
22+
$cArr = explode('\\', 'webfiori\\framework\\autoload\\ClassLoader');
2323
$className = $cArr[count($cArr) - 1];
2424
$classNs = implode('\\', array_slice($cArr, 0, count($cArr) - 1));
2525

26-
$isLoaded = AutoLoader::isLoaded($className, $classNs);
26+
$isLoaded = ClassLoader::isLoaded($className, $classNs);
2727
$this->assertTrue($isLoaded);
2828
}
2929
/**
3030
* @test
3131
*/
3232
public function test02() {
33-
$isLoaded = AutoLoader::isLoaded('AutoLoader');
33+
$isLoaded = ClassLoader::isLoaded('ClassLoader');
3434
$this->assertTrue($isLoaded);
3535
}
3636
}

webfiori/framework/App.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use webfiori\error\Handler;
1818
use webfiori\file\exceptions\FileException;
1919
use webfiori\file\File;
20-
use webfiori\framework\autoload\AutoLoader;
20+
use webfiori\framework\autoload\ClassLoader;
2121
use webfiori\framework\config\ConfigurationDriver;
2222
use webfiori\framework\config\Controller;
2323
use webfiori\framework\exceptions\InitializationException;
@@ -64,7 +64,7 @@ class App {
6464
/**
6565
* An instance of autoloader class.
6666
*
67-
* @var AutoLoader
67+
* @var ClassLoader
6868
*
6969
* @since 1.0
7070
*/
@@ -248,13 +248,13 @@ public static function autoRegister(string $folder, callable $regCallback, strin
248248
}
249249
}
250250
/**
251-
* Returns a reference to an instance of 'AutoLoader'.
251+
* Returns a reference to an instance of 'ClassLoader'.
252252
*
253-
* @return AutoLoader A reference to an instance of 'AutoLoader'.
253+
* @return ClassLoader A reference to an instance of 'ClassLoader'.
254254
*
255255
* @since 1.2.1
256256
*/
257-
public static function getAutoloader(): AutoLoader {
257+
public static function getClassLoader(): ClassLoader {
258258
return self::$AU;
259259
}
260260
/**
@@ -527,10 +527,10 @@ private function initAutoLoader() {
527527
/**
528528
* Initialize autoloader.
529529
*/
530-
if (!class_exists('webfiori\framework\autoload\AutoLoader',false)) {
531-
require_once WF_CORE_PATH.DIRECTORY_SEPARATOR.'autoload'.DIRECTORY_SEPARATOR.'AutoLoader.php';
530+
if (!class_exists('webfiori\framework\autoload\ClassLoader',false)) {
531+
require_once WF_CORE_PATH.DIRECTORY_SEPARATOR.'autoload'.DIRECTORY_SEPARATOR.'ClassLoader.php';
532532
}
533-
self::$AU = AutoLoader::get();
533+
self::$AU = ClassLoader::get();
534534

535535
if (!class_exists(APP_DIR.'\ini\InitAutoLoad')) {
536536
Ini::createAppDirs();

webfiori/framework/autoload/AutoLoader.php renamed to webfiori/framework/autoload/ClassLoader.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
namespace webfiori\framework\autoload;
1212

1313
use Exception;
14-
use webfiori\framework\autoload\ClassInfo;
15-
use webfiori\framework\exceptions\ClassLoaderException;
1614
/**
1715
* An autoloader class to load classes as needed during runtime.
1816
*
@@ -28,7 +26,7 @@
2826
*
2927
* @version 1.1.7
3028
*/
31-
class AutoLoader {
29+
class ClassLoader {
3230
/**
3331
* The name of the file that represents autoloader's cache.
3432
* @var string
@@ -68,9 +66,9 @@ class AutoLoader {
6866
*/
6967
private $loadedClasses;
7068
/**
71-
* A single instance of the class 'AutoLoader'.
69+
* A single instance of the class 'ClassLoader'.
7270
*
73-
* @var AutoLoader
71+
* @var ClassLoader
7472
*
7573
* @since 1.0
7674
*/
@@ -138,7 +136,7 @@ private function __construct(string $root = '', array $searchFolders = [], bool
138136
}
139137
spl_autoload_register(function($className)
140138
{
141-
AutoLoader::get()->loadClass($className);
139+
ClassLoader::get()->loadClass($className);
142140
});
143141

144142
if (gettype($onFail) == 'string') {
@@ -153,8 +151,8 @@ private function __construct(string $root = '', array $searchFolders = [], bool
153151
$this->onFail = self::ON_FAIL_ACTIONS[0];
154152
}
155153
$this->loadedClasses[] = [
156-
ClassInfo::NAME => 'AutoLoader',
157-
ClassInfo::NS => substr(self::class, 0, strlen(self::class) - strlen('AutoLoader') - 1),
154+
ClassInfo::NAME => 'ClassLoader',
155+
ClassInfo::NS => substr(self::class, 0, strlen(self::class) - strlen('ClassLoader') - 1),
158156
ClassInfo::PATH => __DIR__,
159157
ClassInfo::CACHED => false
160158
];
@@ -172,7 +170,7 @@ private function __construct(string $root = '', array $searchFolders = [], bool
172170
];
173171
}
174172
/**
175-
* Returns a single instance of the class 'AutoLoader'.
173+
* Returns a single instance of the class 'ClassLoader'.
176174
*
177175
* @param $options array An associative array of options that is used to initialize
178176
* the autoloader. The available options are:
@@ -196,7 +194,7 @@ private function __construct(string $root = '', array $searchFolders = [], bool
196194
* </li>
197195
* </ul>
198196
*
199-
* @return AutoLoader
197+
* @return ClassLoader
200198
*
201199
* @throws Exception
202200
*/
@@ -205,7 +203,7 @@ public static function get(array $options = [
205203
'search-folders' => [],
206204
'root' => '',
207205
'on-load-failure' => self::ON_FAIL_ACTIONS[1]
208-
]): AutoLoader {
206+
]): ClassLoader {
209207
$DS = DIRECTORY_SEPARATOR;
210208

211209
if (self::$loader === null) {
@@ -243,7 +241,7 @@ public static function get(array $options = [
243241
$root = $DS.$root;
244242
}
245243
$onFail = $options['on-load-failure'] ?? self::ON_FAIL_ACTIONS[0];
246-
self::$loader = new AutoLoader($root, $frameworkSearchFolders, $defineRoot,$onFail);
244+
self::$loader = new ClassLoader($root, $frameworkSearchFolders, $defineRoot,$onFail);
247245
self::checkComposer();
248246
}
249247

0 commit comments

Comments
 (0)