forked from dszulist/mkphp-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.php
More file actions
49 lines (41 loc) · 1.25 KB
/
Loader.php
File metadata and controls
49 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Loader
*
* Klasa obsługująca ładowanie innych klas
*
* @category MK
* @package MK_Loader
*/
class MK_Loader
{
/**
* Funkcja ładujaca klasy zrobiona pod Brokera
* @static
*
* @param string $className
*
* @throws \Exception
* @return bool
*/
public static function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($a = APP_PATH . DIRECTORY_SEPARATOR . $fileName)) { //to tez myk :)
require_once $a;
return true;
} elseif (file_exists($a = DIR_VENDOR . DIRECTORY_SEPARATOR . $fileName)) {
require_once $a;
return true;
}
throw new MK_Loader_Exception('Nie można załadować komponentu systemu.' . $className);
}
}