summaryrefslogtreecommitdiffstats
path: root/autoLoader.php
diff options
context:
space:
mode:
Diffstat (limited to 'autoLoader.php')
-rw-r--r--autoLoader.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/autoLoader.php b/autoLoader.php
new file mode 100644
index 0000000..a7b54d5
--- /dev/null
+++ b/autoLoader.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author stev leibelt <artodeto@bazzline.net>
+ * @since 2014-08-13
+ */
+
+if (function_exists('spl_autoload_register')) {
+ //own autoloader - since support is from php 5 up, no namespaces are available so back to pear style
+ function classLoader($className) {
+ $classNameAsPath = str_replace('_', DIRECTORY_SEPARATOR, $className);
+
+ //keep the most important file path on top
+ $directories = array(
+ __DIR__ . DIRECTORY_SEPARATOR . 'chat' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'class',
+ __DIR__ . DIRECTORY_SEPARATOR . 'source'
+ );
+ $isLoaded = false;
+ $filePath = '';
+
+ foreach ($directories as $directory) {
+ $filePath = $directory . DIRECTORY_SEPARATOR . $classNameAsPath . '.php';
+
+ if (is_file($filePath)) {
+ require_once $filePath;
+ $isLoaded = true;
+ break;
+ }
+ }
+
+ if (!$isLoaded) {
+ throw new Exception(
+ 'can not load class "' . $className . '"' . PHP_EOL .
+ 'last try with path "' . $filePath . '"'
+ );
+ }
+ }
+ spl_autoload_register('classLoader');
+} else {
+ throw new Exception(
+ 'spl_autoload_register function is missing but needed'
+ );
+}