tt-rss/include/autoload.php
Andrew Dolgov 2aaefbfa54 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
2018-06-20 14:58:09 +03:00

22 lines
798 B
PHP

<?php
require_once "functions.php";
spl_autoload_register(function($class) {
list ($namespace, $class_name) = explode('\\', $class, 2);
$root_dir = dirname(__DIR__); // we're in tt-rss/include
// 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;
});