Revert "Revert "Share REST call code and separate components via dependency injection""

This commit is contained in:
Lorenzo Yario
2024-03-30 22:34:30 -07:00
committed by GitHub
parent 4094437464
commit 67475c2c2f
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;
}
}