index/src/Http/ContentHandling/BencodeContentHandler.php

27 lines
727 B
PHP
Raw Normal View History

2024-03-28 22:30:06 +00:00
<?php
// BencodeContentHandler.php
// Created: 2024-03-28
// Updated: 2024-10-02
2024-03-28 22:30:06 +00:00
namespace Index\Http\ContentHandling;
use Index\Bencode\IBencodeSerializable;
2024-03-28 22:30:06 +00:00
use Index\Http\HttpResponseBuilder;
use Index\Http\Content\BencodedContent;
/**
* Represents a Bencode content handler for building HTTP response messages.
*/
2024-03-28 22:30:06 +00:00
class BencodeContentHandler implements IContentHandler {
public function match(mixed $content): bool {
return $content instanceof IBencodeSerializable;
2024-03-28 22:30:06 +00:00
}
public function handle(HttpResponseBuilder $response, mixed $content): void {
if(!$response->hasContentType())
$response->setTypePlain();
$response->setContent(new BencodedContent($content));
}
}