summaryrefslogtreecommitdiff
path: root/include/autoload.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-06-20 14:58:09 +0300
committerAndrew Dolgov <[email protected]>2018-06-20 14:58:09 +0300
commit2aaefbfa54447c37a74aaf126f864fac629e9bd5 (patch)
tree971c158cde0e95b7610c0a3d3072c45338cddd7d /include/autoload.php
parentd00d515320adb57165f7a69bd1c9afc72d51b87f (diff)
update autoloader to consider namespaces for third party libraries: placed and loaded from vendor/namespace/classpath.php
update readability to a newer implementation based on Readability.js (https://github.com/andreskrey/readability.php) add vendor/Psr/Log interface required for the above
Diffstat (limited to 'include/autoload.php')
-rw-r--r--include/autoload.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/include/autoload.php b/include/autoload.php
index 3ab998b75..2e73a9722 100644
--- a/include/autoload.php
+++ b/include/autoload.php
@@ -2,12 +2,21 @@
require_once "functions.php";
spl_autoload_register(function($class) {
- $class_file = str_replace("_", "/", strtolower(basename($class)));
+ list ($namespace, $class_name) = explode('\\', $class, 2);
- $file = dirname(__FILE__)."/../classes/$class_file.php";
+ $root_dir = dirname(__DIR__); // we're in tt-rss/include
- if (file_exists($file)) {
- require $file;
+ // 1. third party libraries with namespaces are loaded from vendor/
+ // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces
+ // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?)
+
+ if ($namespace && $class_name) {
+ $class_file = "$root_dir/vendor/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
+ } else {
+ $class_file = "$root_dir/classes/" . str_replace("_", "/", strtolower($class)) . ".php";
}
+ if (file_exists($class_file))
+ include $class_file;
+
});