summaryrefslogtreecommitdiff
path: root/core/autoload.php
diff options
context:
space:
mode:
authorGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
committerGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
commit02608271bb2a9f3a65ed536984d306ee14b48e34 (patch)
tree3f23ec48a694ec014e845c4f70d9b5f1c065403c /core/autoload.php
downloadkalassa-master.tar.gz
kalassa-master.tar.bz2
kalassa-master.zip
initialize repository; add docker config; migrate configuration to new specsHEADmaster
Diffstat (limited to 'core/autoload.php')
-rw-r--r--core/autoload.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/core/autoload.php b/core/autoload.php
new file mode 100644
index 0000000..c72c335
--- /dev/null
+++ b/core/autoload.php
@@ -0,0 +1,43 @@
+<?php
+/** register class-autoloader
+ *
+ * NOTE:
+ * Composer is strongly recommended; it is a much better option
+ * and takes care for many more than just autoloading classes;
+ *
+ * This's a fair autoloader in case composer is not available;
+ * supports single and namespaced classes.
+ */
+spl_autoload_register(
+ function($className) {
+
+ // in order to support common namespaced classes
+ // replace '\' with '/' to get the path
+ $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
+
+ // check all possible classPaths for class
+ foreach(CLASSPATHS as $key => $basePath) {
+
+ $file = WEB_ROOT . $basePath . $classPath .'.php';
+
+ // if class-file exist, include it
+ if (file_exists($file)) {
+ require_once $file;
+ break;
+ }
+
+ }
+
+ // // Feel free to extend the fanctionality
+ // // example:
+ // // custom (exception) namespaced classes loader
+ // $customNSclasses = array(
+ // '\\George\\Class' => 'path/to/George/Class',
+ // '\\Mary\\Class' => 'path/to/Marias/Class',
+ // ...
+ // );
+ // if array_key_exists($className) {
+ // require_once $customNSclasses[$className];
+ // }
+ }
+);