Bearsampp
2025.8.29
Loading...
Searching...
No Matches
class.autoloader.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
16
class
Autoloader
17
{
23
public
function
__construct
()
24
{
25
}
26
33
public
function
load
($class)
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
}
68
74
public
function
register
()
75
{
76
return
spl_autoload_register(array($this,
'load'
));
77
}
78
84
public
function
unregister
()
85
{
86
return
spl_autoload_unregister(array($this,
'load'
));
87
}
88
}
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
Autoloader
Definition
class.autoloader.php:17
Autoloader\__construct
__construct()
Definition
class.autoloader.php:23
Autoloader\unregister
unregister()
Definition
class.autoloader.php:84
Autoloader\load
load($class)
Definition
class.autoloader.php:33
Util\startWith
static startWith($string, $search)
Definition
class.util.php:154
Bearsampp-development
sandbox
core
classes
class.autoloader.php
Generated by
1.14.0