2024.8.23
Loading...
Searching...
No Matches
Autoloader Class Reference

Public Member Functions

 __construct ()
 
 load ($class)
 
 register ()
 
 unregister ()
 

Detailed Description

Class Autoloader

This class handles the autoloading of classes within the Bearsampp application. It registers itself with the SPL autoload stack and loads classes based on naming conventions.

Definition at line 16 of file class.autoloader.php.

Constructor & Destructor Documentation

◆ __construct()

Autoloader::__construct ( )

Autoloader constructor.

Initializes the Autoloader object.

Definition at line 23 of file class.autoloader.php.

24 {
25 }

Member Function Documentation

◆ load()

Autoloader::load ( $class)

Loads the specified class file based on the class name.

Parameters
string$classThe name of the class to load.
Returns
bool True if the class file was successfully loaded, false otherwise.

Definition at line 33 of file class.autoloader.php.

34 {
35 global $bearsamppRoot;
36
37 $class = strtolower($class);
38 $rootPath = $bearsamppRoot->getCorePath();
39
40 $file = $rootPath . '/classes/class.' . $class . '.php';
41 if (Util::startWith($class, 'bin')) {
42 $class = $class != 'bins' ? substr_replace($class, '.', 3, 0) : $class;
43 $file = $rootPath . '/classes/bins/class.' . $class . '.php';
44 } elseif (Util::startWith($class, 'tool')) {
45 $class = $class != 'tools' ? substr_replace($class, '.', 4, 0) : $class;
46 $file = $rootPath . '/classes/tools/class.' . $class . '.php';
47 } elseif (Util::startWith($class, 'app')) {
48 $class = $class != 'apps' ? substr_replace($class, '.', 3, 0) : $class;
49 $file = $rootPath . '/classes/apps/class.' . $class . '.php';
50 } elseif (Util::startWith($class, 'action')) {
51 $class = $class != 'action' ? substr_replace($class, '.', 6, 0) : $class;
52 $file = $rootPath . '/classes/actions/class.' . $class . '.php';
53 } elseif (Util::startWith($class, 'tplapp') && $class != 'tplapp') {
54 $class = substr_replace(substr_replace($class, '.', 3, 0), '.', 7, 0);
55 $file = $rootPath . '/classes/tpls/app/class.' . $class . '.php';
56 } elseif (Util::startWith($class, 'tpl')) {
57 $class = $class != 'tpls' ? substr_replace($class, '.', 3, 0) : $class;
58 $file = $rootPath . '/classes/tpls/class.' . $class . '.php';
59 }
60
61 if (!file_exists($file)) {
62 return false;
63 }
64
65 require_once $file;
66 return true;
67 }
global $bearsamppRoot
static startWith($string, $search)

References $bearsamppRoot, and Util\startWith().

◆ register()

Autoloader::register ( )

Registers the autoloader with the SPL autoload stack.

Returns
bool True on success, false on failure.

Definition at line 74 of file class.autoloader.php.

75 {
76 return spl_autoload_register(array($this, 'load'));
77 }

◆ unregister()

Autoloader::unregister ( )

Unregisters the autoloader from the SPL autoload stack.

Returns
bool True on success, false on failure.

Definition at line 84 of file class.autoloader.php.

85 {
86 return spl_autoload_unregister(array($this, 'load'));
87 }

The documentation for this class was generated from the following file: