]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Autoload.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Autoload.php
1 <?php
2 /**
3  * Phergie
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
9  * This source file is subject to the new BSD license that is bundled
10  * with this package in the file LICENSE.
11  * It is also available through the world-wide-web at this URL:
12  * http://phergie.org/license
13  *
14  * @category  Phergie
15  * @package   Phergie
16  * @author    Phergie Development Team <team@phergie.org>
17  * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18  * @license   http://phergie.org/license New BSD License
19  * @link      http://pear.phergie.org/package/Phergie
20  */
21
22 /**
23  * Autoloader for Phergie classes.
24  *
25  * @category Phergie
26  * @package  Phergie
27  * @author   Phergie Development Team <team@phergie.org>
28  * @license  http://phergie.org/license New BSD License
29  * @link     http://pear.phergie.org/package/Phergie
30  */
31 class Phergie_Autoload
32 {
33     /**
34      * Constructor to add the base Phergie path to the include_path.
35      *
36      * @return void
37      */
38     public function __construct()
39     {
40         $path = realpath(dirname(__FILE__) . '/..');
41         $includePath = get_include_path();
42         $includePathList = explode(PATH_SEPARATOR, $includePath);
43         if (!in_array($path, $includePathList)) {
44             self::addPath($path);
45         }
46     }
47
48     /**
49      * Autoload callback for loading class files.
50      *
51      * @param string $class Class to load
52      *
53      * @return void
54      */
55     public function load($class)
56     {
57         include str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
58     }
59
60     /**
61      * Registers an instance of this class as an autoloader.
62      *
63      * @return void
64      */
65     public static function registerAutoloader()
66     {
67         spl_autoload_register(array(new self, 'load'));
68     }
69
70     /**
71      * Add a path to the include path.
72      *
73      * @param string $path Path to add
74      *
75      * @return void
76      */
77     public static function addPath($path)
78     {
79         set_include_path($path . PATH_SEPARATOR . get_include_path());
80     }
81 }