Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add php autoloader #2655

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function create($name) {
throw new \Exception('Action ' . $name . ' does not exist!');
}

require_once $filePath;

$class = $this->buildClassName($name);

if((new \ReflectionClass($class))->isInstantiable()) {
Expand Down
2 changes: 0 additions & 2 deletions lib/BridgeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function create($name){
throw new \Exception('Bridge file ' . $filePath . ' does not exist!');
}

require_once $filePath;

if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function create($name){
throw new \Exception('Cache file ' . $filePath . ' does not exist!');
}

require_once $filePath;

if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/FormatFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public function create($name){
throw new \Exception('Format file ' . $filePath . ' does not exist!');
}

require_once $pathFormat;

if((new \ReflectionClass($name))->isInstantiable()) {
return new $name();
}
Expand Down
16 changes: 16 additions & 0 deletions lib/rssbridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@
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();
1 change: 0 additions & 1 deletion tests/ActionImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function dataActionsProvider() {
}

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();
Expand Down
1 change: 0 additions & 1 deletion tests/BridgeImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public function dataBridgesProvider() {
}

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();
Expand Down
1 change: 0 additions & 1 deletion tests/CacheImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function dataCachesProvider() {
}

private function setCache($path) {
require_once $path;
$this->class = basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
}
Expand Down
1 change: 0 additions & 1 deletion tests/FormatImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function dataFormatsProvider() {
}

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();
Expand Down