blob: 442389f8187f9c9b66e5cad66398edee1721ac48 (
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
|
<?php
// This autoloader provide convinient way to working with mock object
// make the test looks natural. This autoloader support cascade file loading as well
// within mocks directory.
//
// Prototype :
//
// include_once('Mock_Core_Common') // Will load ./mocks/core/common.php
// $mock_loader = new Mock_Core_Loader(); // Will load ./mocks/core/loader.php
// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
function autoload($class)
{
$class = (strpos($class, 'Mock_') === 0) ? str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class) : $class;
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$file = $dir.strtolower($class).'.php';
if ( ! file_exists($file))
{
$trace = debug_backtrace();
// If the autoload call came from `class_exists`, we skipped
// and return FALSE
if ($trace[2]['function'] == 'class_exists')
{
return FALSE;
}
throw new InvalidArgumentException("Unable to load $class.");
}
include_once($file);
}
|