Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured fields #27

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from Rfc8941
* @extends Item<bool>
*/
final class Boolean extends Item
{
/**
* @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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from Rfc8941
* @extends Item<string>
*/
final class Bytes extends Item
{
/**
* @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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from Rfc8941
* @extends Item<int>
*/
final class Date extends Item
{
/**
* @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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941Parameters from Rfc8941
* @extends Item<string>
*/
final class DisplayString extends Item
{
/**
* @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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @psalm-import-type Rfc8941SingleItem from Rfc8941
* @psalm-import-type Rfc8941Parameters from Rfc8941
* @extends Item<list<Item<scalar>>>
*/
final class InnerList extends Item
{
/**
* @psalm-param list<Rfc8941SingleItem> $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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

/**
* @template-covariant Inner of scalar|list<Item<scalar>>
* @psalm-import-type Rfc8941Parameters from Rfc8941
*/
abstract class Item
{
/**
* @param Inner $item
* @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 declare(strict_types=1);

namespace Amp\Http\StructuredFields;

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