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 f332d58
Show file tree
Hide file tree
Showing 12 changed files with 799 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
18 changes: 18 additions & 0 deletions src/StructuredFields/Boolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Amp\Http\StructuredFields;

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

namespace Amp\Http\StructuredFields;

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

namespace Amp\Http\StructuredFields;

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

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @template-extends Item<string>
*/
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
* @psalm-import-type Rfc8941BareItem from \Amp\Http\StructuredFields\Rfc8941
* @template-extends Item<list<Item<Rfc8941BareItem>>>
*/
class InnerList extends Item
{
/**
* @psalm-param list<Item<Rfc8941BareItem>> $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;

/**
* @template-covariant Inner
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
*/
class Item
{
/**
* @psalm-param Inner $item
* @psalm-param Rfc8941Parameters $parameters
*/
protected function __construct(public readonly int|float|string|bool|array $item, public readonly array $parameters)
{
}
}
18 changes: 18 additions & 0 deletions src/StructuredFields/Number.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from \Amp\Http\StructuredFields\Rfc8941
* @template-extends Item<int|float>
*/
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 f332d58

Please sign in to comment.