root/tags/RELEASE_0_1_1/XJConf/XJConfLoader.php

Revision 9, 2.1 kB (checked in by mikey, 2 years ago)

added and corrected doc blocks

Line 
1 <?php
2 /**
3  * Class loader for all XJConf classes.
4  *
5  * @author  Frank Kleine <frank.kleine@schlund.de>
6  */
7 /**
8  * Class loader for all XJConf classes.
9  *
10  * The class loader takes care that all class files are only loaded once. It
11  * allows all classes to include the required files without knowing where they
12  * reside or if they have been loaded before.
13  *
14  * @package  XJConf
15  */
16 class XJConfLoader
17 {
18     /**
19      * list of loaded files
20      *
21      * @var  array<String>
22      */
23     private static $loadedFiles = array();
24     
25     /**
26      * method to load files from source path
27      *
28      * Usage: XJConfLoader::load('path.to.Classfile');
29      * or load more than one at once:
30      * XJConfLoader::load('path.to.first.Class',
31                           'path.to.second.Class'
32        );
33      * You may name as many files as you like, there is no restriction
34      * on the number of arguments.
35      *
36      * @param   string  list of file names to load
37      */
38     public static function load()
39     {
40         $files = func_get_args();
41         if (count($files) == 0) {
42             // its ok to call this without any arguments, this won't cause any harm
43             return;
44         }
45         
46         $realFiles = array();
47         foreach ($files as $file) {
48             array_push($realFiles, self::mapClassname($file));
49         }
50         
51         foreach ($realFiles as $filename) {
52             if (in_array($filename, self::$loadedFiles) == TRUE) {
53                 continue; // step to next file if file is already loaded
54             }
55             
56             // save filename before include to prevent endless loop
57             array_push(self::$loadedFiles, $filename);
58             require(dirname(__FILE__) . '/' . $filename);
59         }
60     }
61     
62     /**
63      * maps classnames given to loadClass() into required ones for load()
64      *
65      * @param  string  $classname  name of class given to loadClass()
66      * @return string  name of class required for load()
67      */
68     private static function mapClassname($classname)
69     {
70         return str_replace('.', '/', $classname) . '.php';
71     }
72 }
73 ?>
Note: See TracBrowser for help on using the browser.