use composer-provided autoloader if it exists
[phorkie.git] / src / phorkie / autoload.php
1 <?php
2 /**
3  * Autoloader setup for phorkie
4  *
5  * @author Christian Weiske <cweiske@cweiske.de>
6  */
7 if (file_exists(__DIR__ . '/../../lib/autoload.php')) {
8     //composer-installed dependencies available
9     set_include_path(
10         __DIR__ . '/../'
11         . PATH_SEPARATOR . '.'
12     );
13     require_once __DIR__ . '/../../lib/autoload.php';
14 } else {
15     //use default include path for dependencies
16     set_include_path(
17         __DIR__ . '/../'
18         . PATH_SEPARATOR . get_include_path()
19     );
20 }
21
22 spl_autoload_register(
23     function ($class) {
24         $file = str_replace(array('\\', '_'), '/', $class) . '.php';
25         if (stream_resolve_include_path($file)) {
26             require $file;
27         }
28     }
29 );
30 ?>