Skip to content

Commit 7c56c29

Browse files
Merge pull request #426 from JLG-WOCFR-DEV/codex/fix-class-not-found-error-in-blc-plugin
Add PSR-4 autoloader for plugin namespaces
2 parents 1df3aec + bd00e81 commit 7c56c29

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
spl_autoload_register(
4+
static function ($class) {
5+
$prefix = 'JLG\\BrokenLinks\\';
6+
$prefix_length = strlen($prefix);
7+
8+
if (strncmp($class, $prefix, $prefix_length) !== 0) {
9+
return;
10+
}
11+
12+
$relative_class = substr($class, $prefix_length);
13+
$relative_path = str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
14+
$file = __DIR__ . DIRECTORY_SEPARATOR . $relative_path;
15+
16+
if (is_readable($file)) {
17+
require_once $file;
18+
}
19+
}
20+
);

liens-morts-detector-jlg/liens-morts-detector-jlg.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// Définir les constantes utiles du plugin
1717
define('BLC_PLUGIN_PATH', plugin_dir_path(__FILE__));
1818

19+
require_once BLC_PLUGIN_PATH . 'includes/autoload.php';
20+
1921
if (!defined('BLC_HTTP_BAD_REQUEST')) {
2022
define('BLC_HTTP_BAD_REQUEST', 400);
2123
}

0 commit comments

Comments
 (0)