]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Autoload.php
Added Phergie PHP IRC library
[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 = 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         if (substr($class, 0, 8) == 'Phergie_') {
58             $class = substr($class, 8);
59         }
60         include str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
61     }
62
63     /**
64      * Registers an instance of this class as an autoloader.
65      *
66      * @return void
67      */
68     public static function registerAutoloader()
69     {
70         spl_autoload_register(array(new self, 'load'));
71     }
72
73     /**
74      * Add a path to the include path.
75      *
76      * @param string $path Path to add
77      *
78      * @return void
79      */
80     public static function addPath($path)
81     {
82         set_include_path($path . PATH_SEPARATOR . get_include_path());
83     }
84 }