Passed
Push — master ( c18b9b...a4afd4 )
by Terry
08:43
created

simplecache_autoload()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
/*
3
 * This file is part of the Shieldon Simple Cache 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 simplecache_register()
19
{
20
    spl_autoload_register('simplecache_autoload', true, false);
21
}
22
23
/**
24
 * PSR-4 autoloader.
25
 *
26
 * @param string $className
27
 * 
28
 * @return void
29
 */
30
function simplecache_autoload($className)
31
{
32
    $prefix = 'Shieldon\\SimpleCache\\';
33
    $dir = __DIR__ . '/src/SimpleCache';
34
35
    if (0 === strpos($className, $prefix)) {
36
        $parts = explode('\\', substr($className, strlen($prefix)));
37
        $filepath = $dir . '/' . implode('/', $parts) . '.php';
38
39
        if (is_file($filepath)) {
40
            require $filepath;
41
        }
42
    }
43
}
44
45
simplecache_register();