blob: 151081c1cc6bd86e6319ad67c9c3962ca2196d2d (
plain)
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
|
<?php
namespace Core;
/**
* Loader class
*
* @package core
* @author Frederic Guillot
*/
class Loader
{
/**
* List of paths
*
* @access private
* @var array
*/
private $paths = array();
/**
* Load the missing class
*
* @access public
* @param string $class Class name with namespace
*/
public function load($class)
{
foreach ($this->paths as $path) {
$filename = $path.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($filename)) {
require $filename;
break;
}
}
}
/**
* Register the autoloader
*
* @access public
*/
public function execute()
{
spl_autoload_register(array($this, 'load'));
}
/**
* Register a new path
*
* @access public
* @param string $path Path
* @return Core\Loader
*/
public function setPath($path)
{
$this->paths[] = $path;
return $this;
}
}
|