LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.lepton_autoloader.php
Go to the documentation of this file.
1<?php
2
45function lepton_autoloader(string $aClassName ): bool
46{
47 $lepton_path = dirname(__DIR__, 2);
48
49 $terms = explode("_", $aClassName);
50
51 if ($terms[0] === 'LEPTON')
52 {
53 // We are looking inside the LEPTON-CMS framework directory:
54 $path = $lepton_path."/framework/classes/".strtolower($aClassName).".php";
55 if (file_exists($path))
56 {
57 require_once $path;
58 return true;
59 }
60 }
61 else
62 {
63 // Any module or template specific CLASS
64 $aMainFolders = ["modules", "templates"];
65
66 // [1] Any namespaces given?
67 $aNTest = explode("\\", $aClassName);
68 if (count($aNTest) > 1)
69 {
70 $sPartOne = array_shift($aNTest);
71 $sSubPart = implode("/", $aNTest);
72 foreach ($aMainFolders as $sMainDir)
73 {
74 $path = $lepton_path."/".$sMainDir."/".$sPartOne."/classes/".$sSubPart.".php";
75
76 if (file_exists($path))
77 {
78 require $path;
79 return true;
80 }
81 else
82 {
83 $path = $lepton_path."/".$sMainDir."/".$sPartOne."/".$sSubPart.".php";
84 if (file_exists($path))
85 {
86 require $path;
87 return true;
88 }
89 }
90 }
91 }
92
93 // [2] Non given, nor found
94 $aMainFolders = ["modules", "templates"];
95
96 foreach ($aMainFolders as $sMainDir)
97 {
98 $path = $lepton_path."/".$sMainDir."/".$aClassName."/classes/".$aClassName.".php";
99
100 if (file_exists($path))
101 {
102 require_once $path;
103 return true;
104 }
105 else
106 {
107 $n = count($terms);
108 $look_up = $terms[0];
109
110 for ($i = 0; $i < $n; $i++)
111 {
112 $temp_dir = $look_up . ($i > 0 ? "_" . $terms[$i] : "");
113
114 $path = $lepton_path."/".$sMainDir."/".$temp_dir."/classes/".$aClassName.".php";
115 if (file_exists($path))
116 {
117 require_once $path ;
118 return true;
119 }
120 elseif ($i > 0)
121 {
122 $temp_dir = $look_up."-".$terms[$i];
123 $path = $lepton_path."/".$sMainDir."/".$temp_dir."/classes/".$aClassName.".php";
124 if (file_exists($path))
125 {
126 require_once $path;
127 return true;
128 }
129 }
130
131 $look_up = $temp_dir;
132 }
133 }
134 }
135
136 // [3] account
137 $path = $lepton_path."/".$aClassName."/classes/".$aClassName.".php";
138 if (file_exists($path))
139 {
140 require_once $path;
141 return true;
142 } else {
143 $look_up = $terms[0];
144
145 $path = $lepton_path."/".$look_up."/classes/".$aClassName.".php";
146 if (file_exists($path))
147 {
148 require_once $path;
149 return true;
150 }
151
152 }
153 }
154 return false;
155}
lepton_autoloader(string $aClassName)