refactor: add php autoloader (#2655)

This commit is contained in:
Dag 2022-04-26 00:57:59 +02:00 committed by GitHub
parent b090b17bbf
commit 0ef298f9cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 12 deletions

View file

@ -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()) {

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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');
}

View file

@ -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();