aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2022-04-26 00:57:59 +0200
committerGravatar GitHub <noreply@github.com> 2022-04-26 00:57:59 +0200
commit0ef298f9cc5d2ab74ea9d41706998110fec0308f (patch)
treeef6692c1ddde0cb2adbaa7db0aa2bb139fb41e89
parentb090b17bbf934a102723101911e30796520680b8 (diff)
downloadrss-bridge-0ef298f9cc5d2ab74ea9d41706998110fec0308f.tar.gz
rss-bridge-0ef298f9cc5d2ab74ea9d41706998110fec0308f.tar.zst
rss-bridge-0ef298f9cc5d2ab74ea9d41706998110fec0308f.zip
refactor: add php autoloader (#2655)
-rw-r--r--lib/ActionFactory.php2
-rw-r--r--lib/BridgeFactory.php2
-rw-r--r--lib/CacheFactory.php2
-rw-r--r--lib/FormatFactory.php2
-rw-r--r--lib/rssbridge.php16
-rw-r--r--tests/ActionImplementationTest.php1
-rw-r--r--tests/BridgeImplementationTest.php1
-rw-r--r--tests/CacheImplementationTest.php1
-rw-r--r--tests/FormatImplementationTest.php1
9 files changed, 16 insertions, 12 deletions
diff --git a/lib/ActionFactory.php b/lib/ActionFactory.php
index 46e28c5e..1a0520b5 100644
--- a/lib/ActionFactory.php
+++ b/lib/ActionFactory.php
@@ -27,8 +27,6 @@ class ActionFactory extends FactoryAbstract {
throw new \Exception('Action ' . $name . ' does not exist!');
}
- require_once $filePath;
-
$class = $this->buildClassName($name);
if((new \ReflectionClass($class))->isInstantiable()) {
diff --git a/lib/BridgeFactory.php b/lib/BridgeFactory.php
index fea254f1..5281fa62 100644
--- a/lib/BridgeFactory.php
+++ b/lib/BridgeFactory.php
@@ -68,8 +68,6 @@ class BridgeFactory extends FactoryAbstract {
throw new \Exception('Bridge file ' . $filePath . ' does not exist!');
}
- require_once $filePath;
-
if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
diff --git a/lib/CacheFactory.php b/lib/CacheFactory.php
index 9ce5c19b..441efba1 100644
--- a/lib/CacheFactory.php
+++ b/lib/CacheFactory.php
@@ -54,8 +54,6 @@ class CacheFactory extends FactoryAbstract {
throw new \Exception('Cache file ' . $filePath . ' does not exist!');
}
- require_once $filePath;
-
if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
diff --git a/lib/FormatFactory.php b/lib/FormatFactory.php
index e2bba2fc..c5024e15 100644
--- a/lib/FormatFactory.php
+++ b/lib/FormatFactory.php
@@ -59,8 +59,6 @@ class FormatFactory extends FactoryAbstract {
throw new \Exception('Format file ' . $filePath . ' does not exist!');
}
- require_once $pathFormat;
-
if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
diff --git a/lib/rssbridge.php b/lib/rssbridge.php
index d74af3c3..eccd97bf 100644
--- a/lib/rssbridge.php
+++ b/lib/rssbridge.php
@@ -88,6 +88,22 @@ require_once PATH_LIB_VENDOR . 'parsedown/Parsedown.php';
require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php';
require_once PATH_LIB_VENDOR . 'simplehtmldom/simple_html_dom.php';
+spl_autoload_register(function ($className) {
+ $folders = [
+ __DIR__ . '/../actions/',
+ __DIR__ . '/../bridges/',
+ __DIR__ . '/../caches/',
+ __DIR__ . '/../formats/',
+ __DIR__ . '/../lib/',
+ ];
+ foreach ($folders as $folder) {
+ $file = $folder . $className . '.php';
+ if (is_file($file)) {
+ require $file;
+ }
+ }
+});
+
Configuration::verifyInstallation();
Configuration::loadConfiguration();
Authentication::showPromptIfNeeded();
diff --git a/tests/ActionImplementationTest.php b/tests/ActionImplementationTest.php
index 6a36c2f1..7a3c33f5 100644
--- a/tests/ActionImplementationTest.php
+++ b/tests/ActionImplementationTest.php
@@ -48,7 +48,6 @@ class ActionImplementationTest extends TestCase {
}
private function setAction($path) {
- require_once $path;
$this->class = basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class();
diff --git a/tests/BridgeImplementationTest.php b/tests/BridgeImplementationTest.php
index 28d8ec1e..e45de77f 100644
--- a/tests/BridgeImplementationTest.php
+++ b/tests/BridgeImplementationTest.php
@@ -212,7 +212,6 @@ class BridgeImplementationTest extends TestCase {
}
private function setBridge($path) {
- require_once $path;
$this->class = basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class();
diff --git a/tests/CacheImplementationTest.php b/tests/CacheImplementationTest.php
index 68741d8b..1e430998 100644
--- a/tests/CacheImplementationTest.php
+++ b/tests/CacheImplementationTest.php
@@ -34,7 +34,6 @@ class CacheImplementationTest extends TestCase {
}
private function setCache($path) {
- require_once $path;
$this->class = basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
}
diff --git a/tests/FormatImplementationTest.php b/tests/FormatImplementationTest.php
index d4d7249f..e4501d68 100644
--- a/tests/FormatImplementationTest.php
+++ b/tests/FormatImplementationTest.php
@@ -33,7 +33,6 @@ class FormatImplementationTest extends TestCase {
}
private function setFormat($path) {
- require_once $path;
$this->class = basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class();