diff options
| author | 2020-12-28 19:47:39 +0100 | |
|---|---|---|
| committer | 2020-12-28 19:47:39 +0100 | |
| commit | c246e5d74b1fb88ada602764f247942f2eebc4ca (patch) | |
| tree | 7280a9eeb664e78185618c0088af73d2a5fe2b3d /lib | |
| parent | 465b40f52d758a959747d4d6d6671cb776784e2c (diff) | |
Revert "Extract autoloading process (#3283)"
This reverts commit 46cb89adf842e2fbac254fc99355d6577e4e86eb.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/autoload.php | 74 | ||||
| -rw-r--r-- | lib/lib_rss.php | 29 |
2 files changed, 27 insertions, 76 deletions
diff --git a/lib/autoload.php b/lib/autoload.php deleted file mode 100644 index 5be952876..000000000 --- a/lib/autoload.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -class ClassLoader { - private $searchPath = []; - - /** - * Register path in which to look for a class. - */ - public function registerPath($path) { - if (is_string($path)) { - $this->searchPath[] = $path; - } - if (is_array($path)) { - array_push($this->searchPath, ...$path); - } - } - - /** - * Load class file if found. - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - require $file; - } - } - - /** - * Find the file containing the class definition. - */ - public function findFile($class) { - // This match most of classes directly - foreach ($this->searchPath as $path) { - $file = $path . DIRECTORY_SEPARATOR . str_replace(['\\', '_'], DIRECTORY_SEPARATOR, $class) . '.php'; - if (file_exists($file)) { - return $file; - } - } - - // This match FRSS model classes - $freshrssClass = str_replace('FreshRSS_', '', $class); - foreach ($this->searchPath as $path) { - $file = $path . DIRECTORY_SEPARATOR . str_replace(['\\', '_'], DIRECTORY_SEPARATOR, $freshrssClass) . '.php'; - if (file_exists($file)) { - return $file; - } - } - - // This match FRSS other classes - list(, $classType) = explode('_', $freshrssClass); - foreach ($this->searchPath as $path) { - $file = $path . DIRECTORY_SEPARATOR . $classType . 's' . DIRECTORY_SEPARATOR . str_replace('_', '', $freshrssClass) . '.php'; - if (file_exists($file)) { - return $file; - } - } - } - - /** - * Register the current loader in the autoload queue. - */ - public function register($prepend = false) { - spl_autoload_register([$this, 'loadClass'], true, $prepend); - } -} - -$loader = new ClassLoader(); -$loader->registerPath([ - APP_PATH, - APP_PATH . DIRECTORY_SEPARATOR . 'Models', - LIB_PATH, - LIB_PATH . DIRECTORY_SEPARATOR . 'SimplePie', -]); -$loader->register(); diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 955f0b71e..074982079 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -15,8 +15,6 @@ if (COPY_SYSLOG_TO_STDERR) { openlog('FreshRSS', LOG_CONS | LOG_ODELAY | LOG_PID, LOG_USER); } -require_once LIB_PATH . DIRECTORY_SEPARATOR . 'autoload.php'; - /** * Build a directory path by concatenating a list of directory names. * @@ -28,6 +26,33 @@ function join_path() { return join(DIRECTORY_SEPARATOR, $path_parts); } +//<Auto-loading> +function classAutoloader($class) { + if (strpos($class, 'FreshRSS') === 0) { + $components = explode('_', $class); + switch (count($components)) { + case 1: + include(APP_PATH . '/' . $components[0] . '.php'); + return; + case 2: + include(APP_PATH . '/Models/' . $components[1] . '.php'); + return; + case 3: //Controllers, Exceptions + include(APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php'); + return; + } + } elseif (strpos($class, 'Minz') === 0) { + include(LIB_PATH . '/' . str_replace('_', '/', $class) . '.php'); + } elseif (strpos($class, 'SimplePie') === 0) { + include(LIB_PATH . '/SimplePie/' . str_replace('_', '/', $class) . '.php'); + } elseif (strpos($class, 'PHPMailer') === 0) { + include(LIB_PATH . '/' . str_replace('\\', '/', $class) . '.php'); + } +} + +spl_autoload_register('classAutoloader'); +//</Auto-loading> + function idn_to_puny($url) { if (function_exists('idn_to_ascii')) { $idn = parse_url($url, PHP_URL_HOST); |
