forked from pacbard/gChartPhp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassLoader.php
68 lines (59 loc) · 1.67 KB
/
ClassLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* SPL class loader for gChart classes.
* Code taken from Pheanstalk https://github.com/pda/pheanstalk/blob/master/classes/Pheanstalk/ClassLoader.php and modified
*
*/
class gChart_ClassLoader
{
const PACKAGE = 'gchart';
private static $_path;
/**
* Registers gChart_ClassLoader as an SPL class loader.
* Inserts self first, retains existing loaders and __autoload()
*
* @param string $path Path to gChart
*/
public static function register($path)
{
self::$_path = $path;
self::addPath($path);
if ($loaders = spl_autoload_functions())
array_map('spl_autoload_unregister', $loaders);
else
$loaders = function_exists('__autoload') ? array('__autoload') : array();
$loaders []= array(__CLASS__, 'load');
array_map('spl_autoload_register', $loaders);
}
/**
* Attempts to load a gChart class file.
*
* @param string $class
* @see http://php.net/manual/en/function.spl-autoload-register.php
*/
public static function load($class)
{
//Note: '\' is double escaped
$ns_string = self::PACKAGE.'\\';
if (substr($class, 0, strlen($ns_string)) != $ns_string)
return false;
$path = sprintf(
'%s/%s.php',
self::$_path,
str_replace(self::PACKAGE.'\\', '/', $class)
);
if (file_exists($path)) require_once($path);
}
/**
* @param mixed $items Path or paths as string or array
*/
public static function addPath($items)
{
$elements = explode(PATH_SEPARATOR, get_include_path());
set_include_path(implode(
PATH_SEPARATOR,
array_unique(array_merge((array)$items, $elements))
));
}
}
?>