logbook/func/core/class.php
2025-04-05 23:00:51 +02:00

35 lines
618 B
PHP

<?php
namespace core;
/**
* Requires utils.php to be loaded before
*/
/**
* Autoloading function
*
* @param \string $class_name Name of the class (with namespace)
*
* @throws \Exception
*/
function load_class(string $class_name) : void
{
$path = 'class' . \DIRECTORY_SEPARATOR . # WARNING: hard-coded path
\str_replace('\\', \DIRECTORY_SEPARATOR, $class_name) .
'.class.php';
if (\is_file($path))
{
require_once($path);
}
else
{
\throw new Exception(\core\substitute(
'the class {class} cannot be found in the path {path}',
array('class' => $class_name, 'path' => $path),
))
}
}
?>