developmentAutoloader.php ➔ netBazzlineComponentRequirementDevelopmentAutoloader()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
1
<?php
2
/**
3
 * @param string $className - the name of the class the autoloader should load
4
 * @return bool
5
 * @author stev leibelt <[email protected]>
6
 * @since 2013-06-25
7
 */
8
function netBazzlineComponentRequirementDevelopmentAutoloader($className)
9
{
10
    $namespace = 'Net\\Bazzline\\Component\\Requirement\\';
11
    $lengthOfNamespace = strlen($namespace);
12
    $expectedNamespace = substr($className, 0, $lengthOfNamespace);
13
14
    $isSupportedClassnameByNamespace = ($namespace == $expectedNamespace);
15
16
    if ($isSupportedClassnameByNamespace) {
17
        $classNameWithRemovedNamespace = str_replace($namespace, '', $className);
18
        $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $classNameWithRemovedNamespace) . '.php';
19
        $includePaths = array(
20
            realpath(__DIR__ . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR
21
        );
22
23
        foreach ($includePaths as $includePath) {
24
            $filePath = realpath($includePath . DIRECTORY_SEPARATOR . $fileName);
25
26
            if (file_exists($filePath)) {
27
                require $filePath;
28
29
                break;
30
            } else {
31
                echo var_export(
32
                        array(
33
                            'classname' => $className,
34
                            'filename' => $fileName,
35
                            'filepath' => $filePath,
36
                            'includedPath' => $includePath
37
                        ),
38
                        true
39
                    ) . PHP_EOL;
40
            }
41
        }
42
    } else {
43
        return false;
44
    }
45
}
46
47
spl_autoload_register('netBazzlineComponentRequirementDevelopmentAutoloader');
48