1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Custom autoloader for non-composer installations. |
4
|
|
|
* This function only load classes under 'NelsonMartell' namespace and skips in |
5
|
|
|
* any other case. |
6
|
|
|
* If NML class file is not found, throws and exception. |
7
|
|
|
* |
8
|
|
|
* Note: If you are using "NelsonMartell" as main namespace in a file that not |
9
|
|
|
* belongs to NML, you should include it before to load "NML/autoload.php" or, |
10
|
|
|
* using SPL autoload features, register autoload function for that class(es) |
11
|
|
|
* using "prepend" argument set to TRUE. |
12
|
|
|
* Example, if your autoload function is named "no_NML_autoload_function", you |
13
|
|
|
* can use something like: |
14
|
|
|
* spl_autoload_register("no_NML_autoload_function", true, TRUE). |
15
|
|
|
* |
16
|
|
|
* @param string $class NML class name (full cualified name). |
17
|
|
|
* |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
|
|
function autoload_NML($class) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
static $DS = DIRECTORY_SEPARATOR; |
|
|
|
|
23
|
|
|
|
24
|
|
|
if ($class[0] == '\\') { |
25
|
|
|
$class = substr($class, 1); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$classArray = explode('\\', $class); |
29
|
|
|
|
30
|
|
|
if ($classArray[0] == 'NelsonMartell') { |
31
|
|
|
$classArray[0] = 'src'; |
32
|
|
|
} else { |
33
|
|
|
// Only checks for NelsonMartell namespace. |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$path = sprintf('%s'.$DS.'%s', __DIR__.$DS.'..', implode($DS, $classArray)); |
38
|
|
|
|
39
|
|
|
if (is_file($path.'.php')) { |
40
|
|
|
$path .= '.php'; |
41
|
|
|
} elseif (is_file($path.'.inc')) { |
42
|
|
|
$path .= '.inc'; |
43
|
|
|
} else { |
44
|
|
|
throw new Exception(sprintf(dgettext('nml', 'Unable to auto-load "%s" class in Nelson Martell Library (NML): "%s" file was not found. You can see the API documentation (http://nelson6e65.github.io/php_nml/api) in order to check availability of all classes/namespaces in NML. Note: If you are using "NelsonMartell" as main namespace in a file that not belongs to NML, you should include it before to load "NML/autoload.php" or, using SPL autoload features, register autoload function for that class(es) using "prepend" argument for spl_autoload_register function set to TRUE.'), $class, $path)); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
require_once($path); |
48
|
|
|
} |
|
|
|
|
49
|
|
|
|
Learn more about camelCase.