refactor: improve autoloading
This commit is contained in:
parent
9e6c8877c7
commit
d9d11443c0
18 changed files with 5 additions and 11 deletions
16
index.php
16
index.php
|
@ -21,18 +21,12 @@ require 'vendor/autoload.php';
|
||||||
$include = new \Grandel\IncludeDirectory(__DIR__ . '/src/functions');
|
$include = new \Grandel\IncludeDirectory(__DIR__ . '/src/functions');
|
||||||
|
|
||||||
spl_autoload_register(
|
spl_autoload_register(
|
||||||
function (string $fullClass) {
|
function (string $absoluteNamespace) {
|
||||||
/** Only include classes from this namespace */
|
if (__NAMESPACE__ !== substr($absoluteNamespace, 0, strlen(__NAMESPACE__))) {
|
||||||
if (__NAMESPACE__ === substr($fullClass, 0, strlen(__NAMESPACE__))) {
|
return;
|
||||||
$fullClass = substr($fullClass, strlen(__NAMESPACE__));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = explode('\\', $fullClass);
|
$filepath = ROOT . '/src/classes/' . $absoluteNamespace . '.php';
|
||||||
$class = implode('/', $parts);
|
|
||||||
|
|
||||||
$filepath = ROOT . '/src/classes/' . strtolower($class) . '.php';
|
|
||||||
|
|
||||||
require $filepath;
|
require $filepath;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +89,7 @@ if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database && !$_SESSION['user']->isLog
|
||||||
FROM `sessions`
|
FROM `sessions`
|
||||||
WHERE `session` = :session;',
|
WHERE `session` = :session;',
|
||||||
array(
|
array(
|
||||||
'session' => $_COOKIE[COOKIE_PERSISTENT]
|
'session' => $_COOKIE[COOKIE_PERSISTENT],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->fetchAll();
|
->fetchAll();
|
||||||
|
|
Loading…
Reference in a new issue