mirror of
https://github.com/mashirozx/sakura.git
synced 2024-11-23 07:18:12 +08:00
36 lines
860 B
PHP
36 lines
860 B
PHP
<?php
|
|
/*------------------------------------*\
|
|
Auto loaders
|
|
\*------------------------------------*/
|
|
|
|
// Composer autoload
|
|
require_once(__DIR__ . '/vendor/autoload.php');
|
|
|
|
// Autoload namespace Sakura
|
|
spl_autoload_register(function ($class_name) {
|
|
$namespaces = explode('\\', $class_name);
|
|
$namespaces_length = count($namespaces);
|
|
|
|
if ($namespaces[0] !== 'Sakura') {
|
|
// new Exception("No such class '{$class_name}'");
|
|
return;
|
|
}
|
|
|
|
$path = __DIR__;
|
|
$index = 1;
|
|
|
|
foreach ($namespaces as $namespace) {
|
|
if ($index === 1) {
|
|
$path .= '';
|
|
} elseif ($index < $namespaces_length) {
|
|
$path .= '/' . strtolower($namespace);
|
|
} else {
|
|
$path .= '/' . strtolower(preg_replace('%([a-z])([A-Z])%', '\1-\2', $namespace));
|
|
}
|
|
$index++;
|
|
}
|
|
|
|
// TODO: check if file exists before require
|
|
require_once $path . '.php';
|
|
});
|