-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathautoload.php
More file actions
72 lines (69 loc) · 3.01 KB
/
Copy pathautoload.php
File metadata and controls
72 lines (69 loc) · 3.01 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* This file will autoload KoolReport class when included
*
* @category Core
* @package KoolReport
* @author KoolPHP Inc <support@koolphp.net>
* @copyright 2017-2028 KoolPHP Inc
* @license MIT License https://www.koolreport.com/license#mit-license
* @link https://www.koolphp.net
*/
$packageFolders = glob(dirname(__FILE__)."/../*", GLOB_ONLYDIR);
foreach ($packageFolders as $folder) {
$packageVendorAutoLoadFile = $folder."/vendor/autoload.php";
if (is_file($packageVendorAutoLoadFile)) {
include_once $packageVendorAutoLoadFile;
}
}
spl_autoload_register(
function ($classname) {
if (strpos($classname, "koolreport\\")!==false) {
$dir = str_replace("\\", "/", dirname(__FILE__));
$classname = str_replace("\\", "/", $classname);
$filePath = $dir."/".str_replace("koolreport/", "src/", $classname).".php";
// echo "filePath: $filePath<br>";
//try to load in file
if (is_file($filePath)) {
include_once $filePath;
} else {
//try to load in packages in the same level with core
// $dirSrc = str_replace("\\", "/", dirname(__FILE__));
$dir = str_replace("\\", "/", dirname(dirname(__FILE__)));
$noKoolreportClassName = str_replace("koolreport/", "", $classname);
$filePath = $dir."/".$noKoolreportClassName.".php";
// $packageName = strstr($classname, '/', true);
$packageName = substr($noKoolreportClassName, 0, strpos($noKoolreportClassName, '/'));
$restClassName = substr($noKoolreportClassName, strpos($noKoolreportClassName, '/') + 1);
$filePathSrc = $dir."/". $packageName . "/src/" . $restClassName.".php";
// echo "noKoolreportClassname: $noKoolreportClassname<br>";
// echo "packageName: $packageName<br>";
// echo "restClassName: $restClassName<br>";
// echo "dir: $dir<br>";
// echo "dirSrc: $dirSrc<br>";
// echo "filePath: $filePath<br>";
// echo "filePathSrc: $filePathSrc<br>";
if (is_file($filePath)) {
include_once $filePath;
} else if (is_file($filePathSrc)) {
include_once $filePathSrc;
} else {
//Try to load pakages in packages folder inside core
$dir = str_replace("\\", "/", dirname(__FILE__));
$filePath = $dir."/".str_replace("koolreport/", "packages/", $classname).".php";
// echo "filePath: $filePath<br>";
if (is_file($filePath)) {
include_once $filePath;
}
}
}
}
}
);
// Per-package back-compat alias bootstrap.
foreach ($packageFolders as $folder) {
$packageAliasesFile = $folder . "/aliases.php";
if (is_file($packageAliasesFile)) {
include_once $packageAliasesFile;
}
}