|
Revision 9, 2.1 kB
(checked in by mikey, 2 years ago)
|
added and corrected doc blocks
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 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 |
|
|---|
| 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; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 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 |
?> |
|---|