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

Add headers parsing #22

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

roxblnfk
Copy link
Member

@roxblnfk roxblnfk commented Feb 25, 2021

Q A
New feature? ✔️
Breaks BC?

Related yiisoft/yii-web#355, https://trello.com/c/SoSoY4lY/81-add-headers-parsing-to-http-package

  • Refactor API
  • Refactor tests
    • Separate tests for parser
    • Add more test cases
  • Write docs
  • Decide TODOs
  • Psalm issues
  • Kill mutants

…onstants; create some specific base classes; added Directives group
… and related parameters moved to separate classes
# Conflicts:
#	README.md
#	src/Method.php
@roxblnfk roxblnfk added the status:under development Someone is working on a pull request. label Feb 25, 2021
@roxblnfk roxblnfk marked this pull request as ready for review February 25, 2021 11:47
docs/ru/README.md Show resolved Hide resolved
src/Header/AcceptHeader.php Show resolved Hide resolved
use \Yiisoft\Http\Header\Value\Forwarded;

/** @var \Psr\Http\Message\ServerRequestInterface $request */
$header = Forwarded::createHeader()->withValues($request->getHeader('Forwarded'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about shorter syntax?

Suggested change
$header = Forwarded::createHeader()->withValues($request->getHeader('Forwarded'));
$header = Forwarded::create($request->getHeader('Forwarded'));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forwarded::createHeader as nameless will be Value::createValueCollection, not Value::createValue

docs/ru/http-headers.md Show resolved Hide resolved
Вы можете использовать класс `Date` для конвертирования объекта `\DateTimeInterface` в строку формата времени HTTP.

```php
$date = new \Yiisoft\Http\Header\Value\Date(new DateTimeImmutable('2020-01-01 00:00:00 +0000'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$date = new \Yiisoft\Http\Header\Value\Date(new DateTimeImmutable('2020-01-01 00:00:00 +0000'));
$date = new \Yiisoft\Http\Header\Value\Date::fromDateTime(new DateTimeImmutable('2020-01-01 00:00:00 +0000'));
$date = new \Yiisoft\Http\Header\Value\Date::string('2020-01-01');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you prefer factories over constructors?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if there are multiple ways to create an object.

use Yiisoft\Http\Header\Value\Condition\ETag;
/** @var \Psr\Http\Message\ResponseInterface $response */

$etag = (new ETag())->withTag('56d-9989200-1132c580', true)->inject($response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$etag = (new ETag())->withTag('56d-9989200-1132c580', true)->inject($response);
$etag = (new ETag('56d-9989200-1132c580'))->addToResponse($response);

What is true for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is true for?

public function withTag(string $tag, bool $weak = true): self

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(new ETag('56d-9989200-1132c580')) also possible
(new ETag('W\\56d-9989200-1132c580')) too

Copy link
Member

@samdark samdark Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

$etag = (new ETag('56d-9989200-1132c580'))->weak()->addToResponse($response);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

it is possible. Right now you can not set the weak value saparated from value.
weak() or withWeak()?
Shoul i remove the with prefix in all immutable methods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weak() is alright.

docs/ru/http-headers.md Show resolved Hide resolved
->getValues();

// создать заголовок My-Sorted-List с перечисляемыми сортируемыми значениями
$sorted = \Yiisoft\Http\Header\Value\Unnamed\SortedValue::createHeader('My-Sorted-List')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These namespaces are very long...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants