Share REST call code and separate components via dependency injection

This commit is contained in:
Zankaria
2024-04-01 19:36:03 +02:00
committed by Zankaria
parent c3de90075e
commit 3016d69428
6 changed files with 392 additions and 103 deletions

28
inc/context.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace Vichan;
defined('TINYBOARD') or exit;
use Vichan\Driver\{HttpDriver, HttpDrivers};
interface Context {
public function getHttpDriver(): HttpDriver;
}
class AppContext implements Context {
private array $config;
private ?HttpDriver $http;
public function __construct(array $config) {
$this->config = $config;
}
public function getHttpDriver(): HttpDriver {
if (is_null($this->http)) {
$this->http = HttpDrivers::getHttpDriver($this->config['upload_by_url_timeout'], $this->config['max_filesize']);
}
return $this->http;
}
}