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';
case 'object':
if($value instanceof IBencodeSerialisable)
return self::encode($value->bencodeSerialise(), $depth - 1);
if($value instanceof IBencodeSerializable)
return self::encode($value->bencodeSerialize(), $depth - 1);
$value = get_object_vars($value);
$output = 'd';

View file

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

View file

@ -1,18 +1,18 @@
<?php
// IBencodeSerialisable.php
// Created: 2022-01-13
// Updated: 2024-07-31
// Updated: 2024-10-02
namespace Index\Bencode;
/**
* 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.
*
* @return mixed Representative data.
*/
function bencodeSerialise(): mixed;
function bencodeSerialize(): mixed;
}

View file

@ -5,13 +5,13 @@
namespace Index\Http\Content;
use Index\Bencode\{Bencode,IBencodeSerialisable};
use Index\Bencode\{Bencode,IBencodeSerializable};
use Index\Io\{Stream,FileStream};
/**
* 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.
*/
@ -28,7 +28,7 @@ class BencodedContent implements IHttpContent, IBencodeSerialisable {
return $this->content;
}
public function bencodeSerialise(): mixed {
public function bencodeSerialize(): mixed {
return $this->content;
}

View file

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

View file

@ -1,24 +1,24 @@
<?php
// BencodeSerialisableTest.php
// Created: 2024-09-29
// Updated: 2024-09-30
// Updated: 2024-10-02
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Bencode\{Bencode,BencodeProperty,BencodeSerialisableTrait,IBencodeSerialisable};
use Index\Bencode\{Bencode,BencodeProperty,BencodeSerializableTrait,IBencodeSerializable};
#[CoversClass(BencodeProperty::class)]
#[CoversClass(BencodeSerialisableTrait::class)]
#[CoversClass(BencodeSerializableTrait::class)]
#[UsesClass(Bencode::class)]
#[UsesClass(IBencodeSerialisable::class)]
#[UsesClass(IBencodeSerializable::class)]
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';
public function testBasicBencodedObject(): void {
$test = new class implements IBencodeSerialisable {
use BencodeSerialisableTrait;
$test = new class implements IBencodeSerializable {
use BencodeSerializableTrait;
#[BencodeProperty]
public string $stringVal = 'string value';
@ -118,13 +118,13 @@ final class BencodeSerialisableTest extends TestCase {
#[BencodeProperty('inner')]
public function getObject(): object {
return new class implements IBencodeSerialisable {
use BencodeSerialisableTrait;
return new class implements IBencodeSerializable {
use BencodeSerializableTrait;
#[BencodeProperty('obj')]
public function getObject(): object {
return new class implements IBencodeSerialisable {
use BencodeSerialisableTrait;
return new class implements IBencodeSerializable {
use BencodeSerializableTrait;
#[BencodeProperty('str')]
public function getString(): string {
@ -150,8 +150,8 @@ final class BencodeSerialisableTest extends TestCase {
public function testDoubleBencodedProperty(): void {
$this->expectException(RuntimeException::class);
$test = new class implements IBencodeSerialisable {
use BencodeSerialisableTrait;
$test = new class implements IBencodeSerializable {
use BencodeSerializableTrait;
#[BencodeProperty('test1')]
#[BencodeProperty('test2')]
@ -170,8 +170,8 @@ final class BencodeSerialisableTest extends TestCase {
public function testDuplicateBencodedProperty(): void {
$this->expectException(RuntimeException::class);
$test = new class implements IBencodeSerialisable {
use BencodeSerialisableTrait;
$test = new class implements IBencodeSerializable {
use BencodeSerializableTrait;
#[BencodeProperty]
public string $test1 = 'string value';