autoload.php ➔ kumbia_autoload()   B
last analyzed

Complexity

Conditions 8
Paths 14

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 14
nop 1
dl 0
loc 40
rs 8.0355
c 0
b 0
f 0
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.
9
 *
10
 * @category   Kumbia
11
 * @package    Core
12
 *
13
 * @copyright  Copyright (c) 2005 - 2019 KumbiaPHP Team (http://www.kumbiaphp.com)
14
 * @license    https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE   New BSD License
15
 */
16
17
// @see Util
18
require CORE_PATH.'kumbia/util.php';
19
20
// Autocarga de clases
21
function kumbia_autoload($class)
22
{
23
    // Optimizando carga
24
    static $classes;
25
    if ( ! isset($classes)) {
26
        $classes = [
27
            'ActiveRecord'    => APP_PATH.'libs/active_record.php',
28
            'Load'            => CORE_PATH.'kumbia/load.php',
29
            'KumbiaException' => CORE_PATH.'kumbia/kumbia_exception.php',
30
            'KumbiaRouter'    => CORE_PATH.'kumbia/kumbia_router.php',
31
            'KumbiaFacade'    => CORE_PATH.'kumbia/kumbia_facade.php'
32
        ];
33
    }
34
    if (isset($classes[$class])) {
35
        return include $classes[$class];
36
    }
37
    // PSR0
38
    if (strpos($class, '\\')) {
39
        return kumbia_autoload_vendor($class);
40
    }
41
    // for legacy apps
42
    if ($class === 'Flash') {
43
        return kumbia_autoload_helper('Flash');
44
    }
45
46
    // Convert to smallcase
47
    $sclass = Util::smallcase($class);
48
    if (is_file(APP_PATH."models/$sclass.php")) {
49
        return include APP_PATH."models/$sclass.php";
50
    }
51
    if (is_file(APP_PATH."libs/$sclass.php")) {
52
        return include APP_PATH."libs/$sclass.php";
53
    }
54
    if (is_file(CORE_PATH."libs/$sclass/$sclass.php")) {
55
        return include CORE_PATH."libs/$sclass/$sclass.php";
56
    }
57
    // Perhaps is PEAR,  zend framework 1, ...
58
59
    return kumbia_autoload_vendor($class);
60
}
61
62
function kumbia_autoload_vendor($class)
63
{
64
    //Autoload PSR0
65
    $psr0 = dirname(dirname(APP_PATH)).'/vendor/'.str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class).'.php';
66
    if (is_file($psr0)) {
67
        include $psr0;
68
    }
69
}
70
71
function kumbia_autoload_helper($class)
72
{
73
    $sclass = Util::smallcase($class);
74
    if (is_file(APP_PATH."extensions/helpers/$sclass.php")) {
75
        return include APP_PATH."extensions/helpers/$sclass.php";
76
    }
77
    if (is_file(CORE_PATH."extensions/helpers/$sclass.php")) {
78
        return include CORE_PATH."extensions/helpers/$sclass.php";
79
    }
80
}
81
82
// Registrar la autocarga
83
spl_autoload_register('kumbia_autoload');
84