index/src/Http/ContentHandling/BencodeContentHandler.php

24 lines
648 B
PHP

<?php
// BencodeContentHandler.php
// Created: 2024-03-28
// Updated: 2024-03-28
namespace Index\Http\ContentHandling;
use Index\Http\HttpResponseBuilder;
use Index\Http\Content\BencodedContent;
use Index\Serialisation\IBencodeSerialisable;
class BencodeContentHandler implements IContentHandler {
public function match(mixed $content): bool {
return $content instanceof IBencodeSerialisable;
}
public function handle(HttpResponseBuilder $response, mixed $content): void {
if(!$response->hasContentType())
$response->setTypePlain();
$response->setContent(new BencodedContent($content));
}
}