Skip to content

Commit

Permalink
local host now loads
Browse files Browse the repository at this point in the history
  • Loading branch information
N6REJ committed Dec 18, 2024
1 parent a2ff7a3 commit 67bc7d0
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions core/classes/class.autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* Github: https://github.com/Bearsampp
*/

declare(strict_types=1);

/**
* Class Autoloader
*
* This class handles the autoloading of classes within the Bearsampp application.
* Handles the autoloading of classes within the Bearsampp application.
* It registers itself with the SPL autoload stack and loads classes based on naming conventions.
*/
class Autoloader
{
/**
* Autoloader constructor.
*
* Initializes the Autoloader object.
*/
public function __construct()
Expand All @@ -30,32 +30,34 @@ public function __construct()
* @param string $class The name of the class to load.
* @return bool True if the class file was successfully loaded, false otherwise.
*/
public function load($class)
public function load(string $class): bool
{
global $bearsamppRoot;

$class = strtolower($class);
$class = strtolower($class);
$rootPath = $bearsamppRoot->getCorePath();

$file = $rootPath . '/classes/class.' . $class . '.php';

if (Util::startWith($class, 'bin')) {
$class = $class != 'bins' ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/bins/class.' . $class . '.php';
$classFileName = ($class !== 'bins') ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/bins/class.' . $classFileName . '.php';
} elseif (Util::startWith($class, 'tool')) {
$class = $class != 'tools' ? substr_replace($class, '.', 4, 0) : $class;
$file = $rootPath . '/classes/tools/class.' . $class . '.php';
$classFileName = ($class !== 'tools') ? substr_replace($class, '.', 4, 0) : $class;
$file = $rootPath . '/classes/tools/class.' . $classFileName . '.php';
} elseif (Util::startWith($class, 'app')) {
$class = $class != 'apps' ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/apps/class.' . $class . '.php';
$classFileName = ($class !== 'apps') ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/apps/class.' . $classFileName . '.php';
} elseif (Util::startWith($class, 'action')) {
$class = $class != 'action' ? substr_replace($class, '.', 6, 0) : $class;
$file = $rootPath . '/classes/actions/class.' . $class . '.php';
} elseif (Util::startWith($class, 'tplapp') && $class != 'tplapp') {
$class = substr_replace(substr_replace($class, '.', 3, 0), '.', 7, 0);
$file = $rootPath . '/classes/tpls/app/class.' . $class . '.php';
$classFileName = ($class !== 'action') ? substr_replace($class, '.', 6, 0) : $class;
$file = $rootPath . '/classes/actions/class.' . $classFileName . '.php';
} elseif (Util::startWith($class, 'tplapp') && $class !== 'tplapp') {
$classFileName = substr_replace($class, '.', 3, 0);
$classFileName = substr_replace($classFileName, '.', 7, 0);
$file = $rootPath . '/classes/tpls/app/class.' . $classFileName . '.php';
} elseif (Util::startWith($class, 'tpl')) {
$class = $class != 'tpls' ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/tpls/class.' . $class . '.php';
$classFileName = ($class !== 'tpls') ? substr_replace($class, '.', 3, 0) : $class;
$file = $rootPath . '/classes/tpls/class.' . $classFileName . '.php';
}

if (!file_exists($file)) {
Expand All @@ -71,18 +73,18 @@ public function load($class)
*
* @return bool True on success, false on failure.
*/
public function register()
public function register(): bool
{
return spl_autoload_register(array($this, 'load'));
return spl_autoload_register([$this, 'load']);
}

/**
* Unregisters the autoloader from the SPL autoload stack.
*
* @return bool True on success, false on failure.
*/
public function unregister()
public function unregister(): bool
{
return spl_autoload_unregister(array($this, 'load'));
return spl_autoload_unregister([$this, 'load']);
}
}

0 comments on commit 67bc7d0

Please sign in to comment.