Removed the British to be consistent with JSON.

This commit is contained in:
flash 2024-10-02 01:37:18 +00:00
parent d9a7b04a3b
commit 3e7d443689
7 changed files with 29 additions and 29 deletions

View file

@ -1 +1 @@
0.2410.20133 0.2410.20136

View file

@ -59,8 +59,8 @@ final class Bencode {
return $output . 'e'; return $output . 'e';
case 'object': case 'object':
if($value instanceof IBencodeSerialisable) if($value instanceof IBencodeSerializable)
return self::encode($value->bencodeSerialise(), $depth - 1); return self::encode($value->bencodeSerialize(), $depth - 1);
$value = get_object_vars($value); $value = get_object_vars($value);
$output = 'd'; $output = 'd';

View file

@ -1,7 +1,7 @@
<?php <?php
// BencodeSerialisableTrait.php // BencodeSerialisableTrait.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-30 // Updated: 2024-10-02
namespace Index\Bencode; namespace Index\Bencode;
@ -13,13 +13,13 @@ use RuntimeException;
/** /**
* Implements support for the BencodeProperty attribute. * Implements support for the BencodeProperty attribute.
*/ */
trait BencodeSerialisableTrait { trait BencodeSerializableTrait {
/** /**
* Constructs Bencode object based on BencodeProperty attributes. * Constructs Bencode object based on BencodeProperty attributes.
* *
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function bencodeSerialise(): mixed { public function bencodeSerialize(): mixed {
$objectInfo = new ReflectionObject($this); $objectInfo = new ReflectionObject($this);
$props = []; $props = [];

View file

@ -1,18 +1,18 @@
<?php <?php
// IBencodeSerialisable.php // IBencodeSerialisable.php
// Created: 2022-01-13 // Created: 2022-01-13
// Updated: 2024-07-31 // Updated: 2024-10-02
namespace Index\Bencode; namespace Index\Bencode;
/** /**
* Provides an interface for serialising objects for bencoding in a controlled manner. * Provides an interface for serialising objects for bencoding in a controlled manner.
*/ */
interface IBencodeSerialisable { interface IBencodeSerializable {
/** /**
* Gets the data that should represent this object in a Bencode structure. * Gets the data that should represent this object in a Bencode structure.
* *
* @return mixed Representative data. * @return mixed Representative data.
*/ */
function bencodeSerialise(): mixed; function bencodeSerialize(): mixed;
} }

View file

@ -5,13 +5,13 @@
namespace Index\Http\Content; namespace Index\Http\Content;
use Index\Bencode\{Bencode,IBencodeSerialisable}; use Index\Bencode\{Bencode,IBencodeSerializable};
use Index\Io\{Stream,FileStream}; use Index\Io\{Stream,FileStream};
/** /**
* Represents Bencoded body content for a HTTP message. * Represents Bencoded body content for a HTTP message.
*/ */
class BencodedContent implements IHttpContent, IBencodeSerialisable { class BencodedContent implements IHttpContent, IBencodeSerializable {
/** /**
* @param mixed $content Content to be bencoded. * @param mixed $content Content to be bencoded.
*/ */
@ -28,7 +28,7 @@ class BencodedContent implements IHttpContent, IBencodeSerialisable {
return $this->content; return $this->content;
} }
public function bencodeSerialise(): mixed { public function bencodeSerialize(): mixed {
return $this->content; return $this->content;
} }

View file

@ -1,11 +1,11 @@
<?php <?php
// BencodeContentHandler.php // BencodeContentHandler.php
// Created: 2024-03-28 // Created: 2024-03-28
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Http\ContentHandling; namespace Index\Http\ContentHandling;
use Index\Bencode\IBencodeSerialisable; use Index\Bencode\IBencodeSerializable;
use Index\Http\HttpResponseBuilder; use Index\Http\HttpResponseBuilder;
use Index\Http\Content\BencodedContent; use Index\Http\Content\BencodedContent;
@ -14,7 +14,7 @@ use Index\Http\Content\BencodedContent;
*/ */
class BencodeContentHandler implements IContentHandler { class BencodeContentHandler implements IContentHandler {
public function match(mixed $content): bool { public function match(mixed $content): bool {
return $content instanceof IBencodeSerialisable; return $content instanceof IBencodeSerializable;
} }
public function handle(HttpResponseBuilder $response, mixed $content): void { public function handle(HttpResponseBuilder $response, mixed $content): void {

View file

@ -1,24 +1,24 @@
<?php <?php
// BencodeSerialisableTest.php // BencodeSerialisableTest.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-30 // Updated: 2024-10-02
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass}; use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Bencode\{Bencode,BencodeProperty,BencodeSerialisableTrait,IBencodeSerialisable}; use Index\Bencode\{Bencode,BencodeProperty,BencodeSerializableTrait,IBencodeSerializable};
#[CoversClass(BencodeProperty::class)] #[CoversClass(BencodeProperty::class)]
#[CoversClass(BencodeSerialisableTrait::class)] #[CoversClass(BencodeSerializableTrait::class)]
#[UsesClass(Bencode::class)] #[UsesClass(Bencode::class)]
#[UsesClass(IBencodeSerialisable::class)] #[UsesClass(IBencodeSerializable::class)]
final class BencodeSerialisableTest extends TestCase { final class BencodeSerialisableTest extends TestCase {
private const BASIC_BENCODED_ENCODED = 'd9:stringVal12:string value6:intVali1234e9:intStrVal4:56788:floatVal5:12.3411:floatStrVal5:56.787:trueVali1e22:truePossiblyOmittedVali1e8:falseVali0e14:nullValPresent10:scalarValsli0ei1234e5:12.343:stre16:stringVal_method12:string value9:getIntVali1234e11:getFloatVal5:12.3417:getFloatStringVal5:56.7810:getTrueVali1e25:getTruePossiblyOmittedVali1e11:getFalseVali0e17:getNullValPresent13:getScalarValsli0ei1234e5:12.343:stre5:innerd3:objd3:str21:wow this is illegibleee15:getIntStringVal4:5678e'; private const BASIC_BENCODED_ENCODED = 'd9:stringVal12:string value6:intVali1234e9:intStrVal4:56788:floatVal5:12.3411:floatStrVal5:56.787:trueVali1e22:truePossiblyOmittedVali1e8:falseVali0e14:nullValPresent10:scalarValsli0ei1234e5:12.343:stre16:stringVal_method12:string value9:getIntVali1234e11:getFloatVal5:12.3417:getFloatStringVal5:56.7810:getTrueVali1e25:getTruePossiblyOmittedVali1e11:getFalseVali0e17:getNullValPresent13:getScalarValsli0ei1234e5:12.343:stre5:innerd3:objd3:str21:wow this is illegibleee15:getIntStringVal4:5678e';
public function testBasicBencodedObject(): void { public function testBasicBencodedObject(): void {
$test = new class implements IBencodeSerialisable { $test = new class implements IBencodeSerializable {
use BencodeSerialisableTrait; use BencodeSerializableTrait;
#[BencodeProperty] #[BencodeProperty]
public string $stringVal = 'string value'; public string $stringVal = 'string value';
@ -118,13 +118,13 @@ final class BencodeSerialisableTest extends TestCase {
#[BencodeProperty('inner')] #[BencodeProperty('inner')]
public function getObject(): object { public function getObject(): object {
return new class implements IBencodeSerialisable { return new class implements IBencodeSerializable {
use BencodeSerialisableTrait; use BencodeSerializableTrait;
#[BencodeProperty('obj')] #[BencodeProperty('obj')]
public function getObject(): object { public function getObject(): object {
return new class implements IBencodeSerialisable { return new class implements IBencodeSerializable {
use BencodeSerialisableTrait; use BencodeSerializableTrait;
#[BencodeProperty('str')] #[BencodeProperty('str')]
public function getString(): string { public function getString(): string {
@ -150,8 +150,8 @@ final class BencodeSerialisableTest extends TestCase {
public function testDoubleBencodedProperty(): void { public function testDoubleBencodedProperty(): void {
$this->expectException(RuntimeException::class); $this->expectException(RuntimeException::class);
$test = new class implements IBencodeSerialisable { $test = new class implements IBencodeSerializable {
use BencodeSerialisableTrait; use BencodeSerializableTrait;
#[BencodeProperty('test1')] #[BencodeProperty('test1')]
#[BencodeProperty('test2')] #[BencodeProperty('test2')]
@ -170,8 +170,8 @@ final class BencodeSerialisableTest extends TestCase {
public function testDuplicateBencodedProperty(): void { public function testDuplicateBencodedProperty(): void {
$this->expectException(RuntimeException::class); $this->expectException(RuntimeException::class);
$test = new class implements IBencodeSerialisable { $test = new class implements IBencodeSerializable {
use BencodeSerialisableTrait; use BencodeSerializableTrait;
#[BencodeProperty] #[BencodeProperty]
public string $test1 = 'string value'; public string $test1 = 'string value';