forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_autoload.php
56 lines (48 loc) · 1.36 KB
/
_autoload.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
<?php
/**
* Setup autoloading
*/
function ZendTest_Autoloader($class)
{
$class = ltrim($class, '\\');
if (!preg_match('#^(Zend(Test)?|PHPUnit)(\\\\|_)#', $class)) {
return false;
}
// $segments = explode('\\', $class); // preg_split('#\\\\|_#', $class);//
$segments = preg_split('#[\\\\_]#', $class); // preg_split('#\\\\|_#', $class);//
$ns = array_shift($segments);
switch ($ns) {
case 'Zend':
$file = dirname(__DIR__) . '/library/Zend/';
break;
case 'ZendTest':
// temporary fix for ZendTest namespace until we can migrate files
// into ZendTest dir
$file = __DIR__ . '/Zend/';
break;
default:
$file = false;
break;
}
if ($file) {
$file .= implode('/', $segments) . '.php';
if (file_exists($file)) {
return include_once $file;
}
}
$segments = explode('_', $class);
$ns = array_shift($segments);
switch ($ns) {
case 'Zend':
$file = dirname(__DIR__) . '/library/Zend/';
break;
default:
return false;
}
$file .= implode('/', $segments) . '.php';
if (file_exists($file)) {
return include_once $file;
}
return false;
}
spl_autoload_register('ZendTest_Autoloader', true, true);