Skip to content

Commit

Permalink
Merge pull request #228 from WebFiori/dev
Browse files Browse the repository at this point in the history
Refactoring of Autoloader Component
  • Loading branch information
usernane authored Jul 10, 2024
2 parents 72ad4dc + a817e8f commit 701548c
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 90 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


use webfiori\framework\App;
use webfiori\framework\AutoLoader;
use webfiori\framework\autoload\ClassLoader;

$DS = DIRECTORY_SEPARATOR;

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

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

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

if (file_exists($file)) {
Expand All @@ -45,7 +45,7 @@

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

if (file_exists($file)) {
Expand All @@ -57,13 +57,13 @@
}

if ($isAutoloaderLoaded === false) {
fprintf(STDERR, "Error: Unable to find the class 'AutoLoader'.\n");
fprintf(STDERR, "Error: Unable to find the class 'ClassLoader'.\n");
exit(-1);
} else {
fprintf(STDOUT,"Class 'AutoLoader' successfully loaded.\n");
fprintf(STDOUT,"Class 'ClassLoader' successfully loaded.\n");
}
fprintf(STDOUT,"Initializing autoload directories...\n");
AutoLoader::get([
ClassLoader::get([
'search-folders' => [
'tests',
'webfiori',
Expand All @@ -79,8 +79,8 @@
fprintf(STDOUT,"Initializing application...\n");
App::start();
fprintf(STDOUT,'Done.'."\n");
fprintf(STDOUT,'Root Directory: \''.AutoLoader::get()->root().'\'.'."\n");
define('TESTS_PATH', AutoLoader::get()->root().$DS.TESTS_DIRECTORY);
fprintf(STDOUT,'Root Directory: \''.ClassLoader::get()->root().'\'.'."\n");
define('TESTS_PATH', ClassLoader::get()->root().$DS.TESTS_DIRECTORY);
fprintf(STDOUT,'Tests Path: '.TESTS_PATH."\n");
fprintf(STDOUT,'App Path: '.APP_PATH."\n");
fprintf(STDOUT,"---------------------------------\n");
Expand Down
10 changes: 5 additions & 5 deletions tests/webfiori/framework/test/TestAutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace webfiori\framework\test;

use PHPUnit\Framework\TestCase;
use webfiori\framework\AutoLoader;
use webfiori\framework\autoload\ClassLoader;
/**
* Description of TestAutoLoader
*
Expand All @@ -13,24 +13,24 @@ class TestAutoLoader extends TestCase {
* @test
*/
public function test00() {
$this->assertEquals(ROOT_PATH, AutoLoader::root());
$this->assertEquals(ROOT_PATH, ClassLoader::root());
}
/**
* @test
*/
public function test01() {
$cArr = explode('\\', 'webfiori\\entity\\AutoLoader');
$cArr = explode('\\', 'webfiori\\framework\\autoload\\ClassLoader');
$className = $cArr[count($cArr) - 1];
$classNs = implode('\\', array_slice($cArr, 0, count($cArr) - 1));

$isLoaded = AutoLoader::isLoaded($className, $classNs);
$isLoaded = ClassLoader::isLoaded($className, $classNs);
$this->assertTrue($isLoaded);
}
/**
* @test
*/
public function test02() {
$isLoaded = AutoLoader::isLoaded('AutoLoader');
$isLoaded = ClassLoader::isLoaded('ClassLoader');
$this->assertTrue($isLoaded);
}
}
4 changes: 3 additions & 1 deletion tests/webfiori/framework/test/router/RouterUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
namespace webfiori\framework\test\router;

use PHPUnit\Framework\TestCase;
use TestMiddleware;
use webfiori\framework\middleware\MiddlewareManager;
use webfiori\framework\router\Router;
use webfiori\framework\router\RouterUri;
/**
Expand All @@ -15,7 +17,7 @@ class RouterUriTest extends TestCase {
*/
public function testAddToMiddleware00() {
$uri = new RouterUri('https://www3.programmingacademia.com:80/test', '');
\webfiori\framework\middleware\MiddlewareManager::register(new \TestMiddleware());
MiddlewareManager::register(new TestMiddleware());
$uri->addMiddleware('global');
$this->assertEquals(1, $uri->getMiddleware()->size());
$uri->addMiddleware('Super Cool Middleware');
Expand Down
2 changes: 1 addition & 1 deletion tests/webfiori/framework/test/session/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
namespace webfiori\framework\test\session;

use PHPUnit\Framework\TestCase;
use SessionStatus;
use webfiori\file\File;
use webfiori\framework\exceptions\SessionException;
use webfiori\framework\session\Session;
use webfiori\framework\session\SessionStatus;
/**
* Description of SessionTest
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
namespace webfiori\framework\test\session;

use PHPUnit\Framework\TestCase;
use SessionStatus;
use webfiori\database\ConnectionInfo;
use webfiori\database\DatabaseException;
use webfiori\framework\App;
use webfiori\framework\exceptions\SessionException;
use webfiori\framework\session\DatabaseSessionStorage;
use webfiori\framework\session\SessionsManager;
use webfiori\framework\session\SessionStatus;

/**
* Description of SessionsManagerTest
Expand Down
19 changes: 10 additions & 9 deletions webfiori/framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use webfiori\error\Handler;
use webfiori\file\exceptions\FileException;
use webfiori\file\File;
use webfiori\framework\autoload\ClassLoader;
use webfiori\framework\config\ConfigurationDriver;
use webfiori\framework\config\Controller;
use webfiori\framework\exceptions\InitializationException;
Expand Down Expand Up @@ -63,7 +64,7 @@ class App {
/**
* An instance of autoloader class.
*
* @var AutoLoader
* @var ClassLoader
*
* @since 1.0
*/
Expand Down Expand Up @@ -247,13 +248,13 @@ public static function autoRegister(string $folder, callable $regCallback, strin
}
}
/**
* Returns a reference to an instance of 'AutoLoader'.
* Returns a reference to an instance of 'ClassLoader'.
*
* @return AutoLoader A reference to an instance of 'AutoLoader'.
* @return ClassLoader A reference to an instance of 'ClassLoader'.
*
* @since 1.2.1
*/
public static function getAutoloader(): AutoLoader {
public static function getClassLoader(): ClassLoader {
return self::$AU;
}
/**
Expand Down Expand Up @@ -526,10 +527,10 @@ private function initAutoLoader() {
/**
* Initialize autoloader.
*/
if (!class_exists('webfiori\framework\AutoLoader',false)) {
require_once WF_CORE_PATH.DIRECTORY_SEPARATOR.'AutoLoader.php';
if (!class_exists('webfiori\framework\autoload\ClassLoader',false)) {
require_once WF_CORE_PATH.DIRECTORY_SEPARATOR.'autoload'.DIRECTORY_SEPARATOR.'ClassLoader.php';
}
self::$AU = AutoLoader::get();
self::$AU = ClassLoader::get();

if (!class_exists(APP_DIR.'\ini\InitAutoLoad')) {
Ini::createAppDirs();
Expand All @@ -543,7 +544,7 @@ private function initFrameworkVersionInfo() {
*
* @since 2.1
*/
define('WF_VERSION', '3.0.0-Beta.9');
define('WF_VERSION', '3.0.0-Beta.10');
/**
* A constant that tells the type of framework version.
*
Expand All @@ -559,7 +560,7 @@ private function initFrameworkVersionInfo() {
*
* @since 2.1
*/
define('WF_RELEASE_DATE', '2024-07-09');
define('WF_RELEASE_DATE', '2024-07-11');
}

/**
Expand Down
33 changes: 33 additions & 0 deletions webfiori/framework/autoload/ClassInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2024 Ibrahim BinAlshikh
*
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
*/
namespace webfiori\framework\autoload;
/**
* A class that contains the names of indices that are used by loaded class info array.
*
*/
class ClassInfo {
/**
* A constant that represents the value 'name' of class.
*/
const NAME = 'class-name';
/**
* A constant that represents the value 'namespace' of class.
*/
const NS = 'namespace';
/**
* A constant that represents the value 'path' of class.
*/
const PATH = 'path';
/**
* A constant that represents the value 'cached' of class.
*/
const CACHED = 'loaded-from-cache';
}
Loading

0 comments on commit 701548c

Please sign in to comment.