mirror of
https://github.com/php/web-php.git
synced 2026-03-23 23:02:13 +01:00
Enhancement: Use PSR-4 autoloader (#604)
This commit is contained in:
28
autoload.php
Normal file
28
autoload.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/php-fig/fig-standards/blob/a1a0674a742c9d07c5dd450209fb33b115ee7b40/accepted/PSR-4-autoloader-examples.md#closure-example
|
||||
*/
|
||||
spl_autoload_register(static function (string $class): void {
|
||||
$prefix = 'phpweb\\';
|
||||
$directory = __DIR__ . '/src/';
|
||||
|
||||
$length = strlen($prefix);
|
||||
|
||||
if (strncmp($prefix, $class, $length) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$relativeClass = substr(
|
||||
$class,
|
||||
$length
|
||||
);
|
||||
|
||||
$file = $directory . str_replace('\\', '/', $relativeClass) . '.php';
|
||||
|
||||
if (!file_exists($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require $file;
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
PHP_SAPI == 'cli' or die("Please run this script using the cli sapi");
|
||||
|
||||
require_once __DIR__ . '/../src/News/Entry.php';
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use phpweb\News\Entry;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
PHP_SAPI == 'cli' or die("Please run this script using the cli sapi");
|
||||
|
||||
require_once __DIR__ . '/../src/News/Entry.php';
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use phpweb\News\Entry;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ $PGI = array(); $SIDEBAR_DATA = '';
|
||||
// User note display functions
|
||||
// =============================================================================
|
||||
|
||||
require_once __DIR__ . '/../src/UserNotes/Sorter.php';
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
use phpweb\UserNotes\Sorter;
|
||||
|
||||
// Print out all user notes for this manual page
|
||||
|
||||
Reference in New Issue
Block a user