Skip to content

Commit

Permalink
Add RFC 8941 structured field parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Jan 14, 2024
1 parent a19f480 commit 6c63063
Show file tree
Hide file tree
Showing 12 changed files with 804 additions and 0 deletions.
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,24 @@
"require-dev": {
"phpunit/phpunit": "^9",
"amphp/php-cs-fixer-config": "^2",
"httpwg/structured-field-tests": "1.0",
"league/uri": "^6.8 | ^7.1",
"psalm/phar": "^5.4"
},
"repositories": [
{
"type": "package",
"package": {
"name": "httpwg/structured-field-tests",
"version": "1.0",
"source": {
"url": "https://github.com/httpwg/structured-field-tests",
"type": "git",
"reference": "origin/main"
}
}
}
],
"scripts": {
"test": "php -dzend.assertions=1 -dassert.exception=1 vendor/bin/phpunit",
"code-style": "php vendor/bin/php-cs-fixer fix"
Expand Down
19 changes: 19 additions & 0 deletions src/StructuredFields/Boolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read bool $item
* @template-extends Item<void>
*/
class Boolean extends Item
{
/**
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(bool $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
19 changes: 19 additions & 0 deletions src/StructuredFields/Bytes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read string $item
* @template-extends Item<void>
*/
class Bytes extends Item
{
/**
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(string $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
19 changes: 19 additions & 0 deletions src/StructuredFields/Date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read int $item
* @template-extends Item<void>
*/
class Date extends Item
{
/**
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(int $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
19 changes: 19 additions & 0 deletions src/StructuredFields/DisplayString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read string $item
* @template-extends Item<void>
*/
class DisplayString extends Item
{
/**
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(string $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
20 changes: 20 additions & 0 deletions src/StructuredFields/InnerList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read list<Item<void>> $item
* @template-extends Item<list<Item<void>>>
*/
class InnerList extends Item
{
/**
* @psalm-param list<Item<void>> $item
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(array $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
18 changes: 18 additions & 0 deletions src/StructuredFields/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-template Inner
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
*/
class Item
{
/**
* @psalm-param int|float|string|bool|Inner $item

Check failure on line 12 in src/StructuredFields/Item.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

MismatchingDocblockPropertyType

src/StructuredFields/Item.php:12:21: MismatchingDocblockPropertyType: Parameter Amp\Http\StructuredFields\Item::$item has wrong type 'null|scalar', should be 'array<array-key, mixed>|scalar' (see https://psalm.dev/264)

Check failure on line 12 in src/StructuredFields/Item.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

MismatchingDocblockPropertyType

src/StructuredFields/Item.php:12:21: MismatchingDocblockPropertyType: Parameter Amp\Http\StructuredFields\Item::$item has wrong type 'null|scalar', should be 'array<array-key, mixed>|scalar' (see https://psalm.dev/264)
* @psalm-param Rfc8941Parameters $parameters
*/
protected function __construct(public readonly int|float|string|bool|array $item, public readonly array $parameters)
{
}
}
19 changes: 19 additions & 0 deletions src/StructuredFields/Number.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @property-read int|float $item
* @template-extends Item<void>
*/
class Number extends Item
{
/**
* @psalm-param Rfc8941Parameters $parameters
*/
public function __construct(int|float $item, array $parameters)
{
parent::__construct($item, $parameters);
}
}
Loading

0 comments on commit 6c63063

Please sign in to comment.