mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.0
|
|
*
|
|
* @category TBD
|
|
* @package TBD
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @copyright 2013 Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://orange-management.com
|
|
*/
|
|
|
|
namespace phpOMS;
|
|
|
|
spl_autoload_register('\phpOMS\Autoloader::default_autoloader');
|
|
|
|
/**
|
|
* Autoloader class.
|
|
*
|
|
* @category Framework
|
|
* @package Framework
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @license OMS License 1.0
|
|
* @link http://orange-management.com
|
|
* @since 1.0.0
|
|
*/
|
|
class Autoloader
|
|
{
|
|
|
|
/**
|
|
* Loading classes by namespace + class name.
|
|
*
|
|
* @param string $class Class path
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws \Exception Throws this exception if the class to autoload doesn't exist. This could also be related to a wrong namespace/file path correlation.
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public static function default_autoloader(string $class)
|
|
{
|
|
if (($classNew = self::exists($class)) !== false) {
|
|
/** @noinspection PhpIncludeInspection */
|
|
include __DIR__ . '/../' . $classNew . '.php';
|
|
} else {
|
|
throw new \Exception($class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if class exists.
|
|
*
|
|
* @param string $class Class path
|
|
*
|
|
* @return false|string
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public static function exists(string $class)
|
|
{
|
|
$class = ltrim($class, '\\');
|
|
$class = str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class);
|
|
|
|
if (file_exists(__DIR__ . '/../' . $class . '.php')) {
|
|
return $class;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|