use composer-provided autoloader if it exists
authorChristian Weiske <cweiske@cweiske.de>
Thu, 15 May 2014 16:13:49 +0000 (18:13 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 15 May 2014 16:13:49 +0000 (18:13 +0200)
scripts/index.php
scripts/search.php
src/phorkie/autoload.php [new file with mode: 0644]
www/www-header.php

index c1e67af4cb6f04f14d32acdfaadc45ed23d0a12f..1f7a7ac5ce8885869a090bc4a17238a6c7cc7f31 100644 (file)
@@ -2,18 +2,7 @@
 //index repositories in elasticsearch
 
 namespace phorkie;
-set_include_path(
-    __DIR__ . '/../src/'
-    . PATH_SEPARATOR . get_include_path()
-);
-spl_autoload_register(
-    function ($class) {
-        $file = str_replace(array('\\', '_'), '/', $class) . '.php';
-        if (stream_resolve_include_path($file)) {
-            require $file;
-        }
-    }
-);
+require_once __DIR__ . '/../src/phorkie/autoload.php';
 require_once __DIR__ . '/../data/config.default.php';
 if (file_exists(__DIR__ . '/../data/config.php')) {
     require_once __DIR__ . '/../data/config.php';
index d7d1b643ee1b537c608e8cef629d0cd6b54f4c54..121c7e21b51fd5b9d92c379953a9a674ca55e96e 100644 (file)
@@ -2,18 +2,7 @@
 //search
 
 namespace phorkie;
-set_include_path(
-    __DIR__ . '/../src/'
-    . PATH_SEPARATOR . get_include_path()
-);
-spl_autoload_register(
-    function ($class) {
-        $file = str_replace(array('\\', '_'), '/', $class) . '.php';
-        if (stream_resolve_include_path($file)) {
-            require $file;
-        }
-    }
-);
+require_once __DIR__ . '/../src/phorkie/autoload.php';
 require_once __DIR__ . '/../data/config.default.php';
 if (file_exists(__DIR__ . '/../data/config.php')) {
     require_once __DIR__ . '/../data/config.php';
diff --git a/src/phorkie/autoload.php b/src/phorkie/autoload.php
new file mode 100644 (file)
index 0000000..189cde4
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Autoloader setup for phorkie
+ *
+ * @author Christian Weiske <cweiske@cweiske.de>
+ */
+if (file_exists(__DIR__ . '/../../lib/autoload.php')) {
+    //composer-installed dependencies available
+    set_include_path(
+        __DIR__ . '/../'
+        . PATH_SEPARATOR . '.'
+    );
+    require_once __DIR__ . '/../../lib/autoload.php';
+} else {
+    //use default include path for dependencies
+    set_include_path(
+        __DIR__ . '/../'
+        . PATH_SEPARATOR . get_include_path()
+    );
+}
+
+spl_autoload_register(
+    function ($class) {
+        $file = str_replace(array('\\', '_'), '/', $class) . '.php';
+        if (stream_resolve_include_path($file)) {
+            require $file;
+        }
+    }
+);
+?>
index ef948e458782faa42996269236ab1c93618c71d5..b58bd95ed659306b764ca40b67fc381002e0b756 100644 (file)
@@ -2,18 +2,7 @@
 namespace phorkie;
 session_start();
 
-set_include_path(
-    __DIR__ . '/../src/'
-    . PATH_SEPARATOR . get_include_path()
-);
-spl_autoload_register(
-    function ($class) {
-        $file = str_replace(array('\\', '_'), '/', $class) . '.php';
-        if (stream_resolve_include_path($file)) {
-            require $file;
-        }
-    }
-);
+require_once __DIR__ . '/../src/phorkie/autoload.php';
 set_exception_handler(
     function ($e) {
         if ($e instanceof Exception) {