|
Revision 129, 1.8 kB
(checked in by mikey, 1 year ago)
|
renamed XJConfLoader to XJConf
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
namespace net::xjconf; |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
class XJConf |
|---|
| 19 |
{ |
|---|
| 20 |
|
|---|
| 21 |
* method to load files from source path |
|---|
| 22 |
* |
|---|
| 23 |
* @param string list of file names to load |
|---|
| 24 |
*/ |
|---|
| 25 |
public static function load($className) |
|---|
| 26 |
{ |
|---|
| 27 |
if (self::providesClass($className) === false) { |
|---|
| 28 |
return; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
if (substr(__FILE__, 0, 7) === 'star://') { |
|---|
| 32 |
include str_replace(__CLASS__, $className, __FILE__); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
include dirname(__FILE__) . '/' . self::mapClassname($className); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* checks whether a file with the given class exists |
|---|
| 40 |
* |
|---|
| 41 |
* @param string $fqClassName |
|---|
| 42 |
* @return bool |
|---|
| 43 |
*/ |
|---|
| 44 |
public static function providesClass($className) |
|---|
| 45 |
{ |
|---|
| 46 |
if (substr(__FILE__, 0, 7) === 'star://') { |
|---|
| 47 |
return file_exists(str_replace(__CLASS__, $className, __FILE__)); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
return file_exists(dirname(__FILE__) . '/' . self::mapClassname($className)); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
* maps classnames given to loadClass() into required ones for load() |
|---|
| 55 |
* |
|---|
| 56 |
* @param string $classname name of class given to loadClass() |
|---|
| 57 |
* @return string name of class required for load() |
|---|
| 58 |
*/ |
|---|
| 59 |
private static function mapClassname($classname) |
|---|
| 60 |
{ |
|---|
| 61 |
return str_replace('::', '/', str_replace('net::xjconf::', '', $classname)) . '.php'; |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
spl_autoload_register(array('net::xjconf::XJConf', 'load')); |
|---|
| 68 |
?> |
|---|