mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-13 08:59:34 +03:00
feat: new portal selection and favicons
This commit is contained in:
@@ -98,9 +98,10 @@ final class Server implements AppModuleInterface {
|
||||
// $this->bindContext
|
||||
//);
|
||||
$router = new Router($this->httpServer, $this->logger, $this->errorHandler);
|
||||
$httpHandler = HTTPHandler::getInstance($this->logger)->getHandler();
|
||||
$router->addRoute('GET', '/', $httpHandler);
|
||||
$router->addRoute('GET', '/{name:.+}', $httpHandler);
|
||||
$httpHandlerInstance = HTTPHandler::getInstance($this->logger);
|
||||
$router->addRoute('GET', '/', $httpHandlerInstance->getHandler('main'));
|
||||
$router->addRoute('GET', '/favicon', $httpHandlerInstance->getHandler('favicon'));
|
||||
$router->addRoute('GET', '/{name:.+}', $httpHandlerInstance->getHandler('main'));
|
||||
$router->setFallback(new DocumentRoot($this->httpServer, $this->errorHandler, PATH_ROOT . '/public'));
|
||||
|
||||
$this->httpServer->start($router, $this->errorHandler);
|
||||
|
42
src/Infrastructure/Storage/IconsStorage.php
Normal file
42
src/Infrastructure/Storage/IconsStorage.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace OpenCCK\Infrastructure\Storage;
|
||||
|
||||
use OpenCCK\Infrastructure\API\App;
|
||||
use Revolt\EventLoop;
|
||||
|
||||
class IconsStorage implements StorageInterface {
|
||||
const FILENAME = 'icons.json';
|
||||
|
||||
private static IconsStorage $_instance;
|
||||
private array $data = [];
|
||||
|
||||
private function __construct() {
|
||||
$path = PATH_ROOT . '/storage/' . self::FILENAME;
|
||||
if (is_file($path)) {
|
||||
$this->data = (array) json_decode(file_get_contents($path)) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance(): IconsStorage {
|
||||
return self::$_instance ??= new self();
|
||||
}
|
||||
|
||||
public function get(string $key): ?string {
|
||||
return $this->data[$key] ?? null;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value): bool {
|
||||
$this->data[$key] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function has(string $key): bool {
|
||||
return isset($this->data[$key]);
|
||||
}
|
||||
|
||||
public function save(): void {
|
||||
file_put_contents(PATH_ROOT . '/storage/' . self::FILENAME, json_encode($this->data, JSON_PRETTY_PRINT));
|
||||
App::getLogger()->notice('Icons storage saved', [count($this->data) . ' items']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user