Skip to content

Commit

Permalink
refactor: add php autoloader (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Apr 25, 2022
1 parent b090b17 commit 0ef298f
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 12 deletions.
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

0 comments on commit 0ef298f

Please sign in to comment.