Completed
Push — master ( 03cb5f...623b34 )
by Terry
03:06 queued 11s
created

psr_http_autoload()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 1
1
<?php
2
/*
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
/**
14
 * Register to PSR-4 autoloader.
15
 *
16
 * @return void
17
 */
18
function psr_http_register()
19
{
20
    spl_autoload_register('psr_http_autoload', true, false);
21
}
22
23
/**
24
 * PSR-4 autoloader.
25
 *
26
 * @param string $className
27
 * 
28
 * @return void
29
 */
30
function psr_http_autoload($className)
31
{
32
    $prefix = 'Shieldon\\';
33
    $dir = __DIR__ . '/src';
34
35
    if (0 === strpos($className, $prefix . 'Psr')) {
36
        $parts = explode('\\', substr($className, strlen($prefix)));
37
        $filepath = $dir . '/' . implode('/', $parts) . '.php';
38
39
        echo $filepath . '<br >';
40
41
        if (is_file($filepath)) {
42
            require $filepath;
43
        }
44
    }
45
}
46
47
psr_http_register();