Completed
Branch master (9efafe)
by Patrick
03:38
created

Autoload.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
* Flipside Common Code Autoload Function
4
*
5
* Autoload Flipside Common code Classes with the syntax Namespace/class.Classname.php
6
*
7
* @author Patrick Boyd / [email protected]
8
* @copyright Copyright (c) 2015, Austin Artistic Reconstruction
9
* @license http://www.apache.org/licenses/ Apache 2.0 License
10
*/
11
12
/**
13
* Flipside Common Code Autoload Function
14
*
15
* Autoload Flipside Common code Classes with the syntax Namespace/class.Classname.php
16
*
17
* @param string $classname The class name with the namespace to load
18
*/
19
function FlipsideAutoload($classname)
20
{
21
    $classname = str_replace('/', '\\', $classname);
0 ignored issues
show
Consider using a different name than the parameter $classname. This often makes code more readable.
Loading history...
22
    $classname = ltrim($classname, '\\');
0 ignored issues
show
Consider using a different name than the parameter $classname. This often makes code more readable.
Loading history...
23
    $filename  = '';
24
    $namespace = '';
25
    if($lastNsPos = strrpos($classname, '\\'))
26
    {
27
        $namespace = substr($classname, 0, $lastNsPos);
28
        $classname = substr($classname, $lastNsPos + 1);
0 ignored issues
show
Consider using a different name than the parameter $classname. This often makes code more readable.
Loading history...
29
        $filename  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR;
30
    }
31
    $filename = __DIR__.DIRECTORY_SEPARATOR.$filename.'class.'.$classname.'.php';
32
    if(is_readable($filename))
33
    {
34
        require $filename;
35
    }
36
}
37
38
function autoLoadHandler($functionName)
39
{
40
    if(version_compare(PHP_VERSION, '5.3.0', '>='))
41
    {
42
        spl_autoload_register($functionName, true, true);
43
    }
44
    else
45
    {
46
        spl_autoload_register($functionName);
47
    }
48
}
49
50
autoLoadHandler('FlipsideAutoload');
51
52
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
53