1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | if (version_compare(PHP_VERSION, '7.1.0', '<')) { |
||
6 | throw new Exception('This library require PHP 7.1 minimum'); |
||
7 | } |
||
8 | |||
9 | /* |
||
10 | * Register the autoloader. |
||
11 | * Based off the official PSR-4 autoloader example found here: |
||
12 | * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md |
||
13 | * |
||
14 | * @param string $class The fully-qualified class name. |
||
15 | * @return void |
||
16 | */ |
||
17 | spl_autoload_register(function ($class) { |
||
18 | $prefix = 'Rico\\'; |
||
19 | $prefixTest = 'Rico\\Test\\'; |
||
20 | |||
21 | $length = mb_strlen($prefix); |
||
22 | $lengthTest = mb_strlen($prefixTest); |
||
23 | if (0 === strncmp($prefix, $class, $length)) { |
||
24 | $baseDir = defined('UTILITY_BASE_DIR') ? UTILITY_BASE_DIR : __DIR__.'/src/'; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | $relativeClass = mb_substr($class, $length); |
||
26 | } |
||
27 | if (0 === strncmp($prefixTest, $class, $lengthTest)) { |
||
28 | $baseDir = defined('UTILITY_BASE_DIR') ? UTILITY_BASE_DIR : __DIR__.'/tests/'; |
||
29 | $relativeClass = mb_substr($class, $lengthTest); |
||
30 | } |
||
31 | |||
32 | if (empty($baseDir)) { |
||
33 | return; |
||
34 | } |
||
35 | |||
36 | $file = $baseDir.str_replace('\\', '/', $relativeClass).'.php'; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
37 | |||
38 | if (file_exists($file)) { |
||
39 | require $file; |
||
40 | } |
||
41 | }); |
||
42 |