Skip to content

Commit 6579426

Browse files
committed
Prepare 1.1.0 release
1 parent 3eb3ec7 commit 6579426

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All Notable changes to `bakame/http-strucured-fields` will be documented in this file.
44

5-
## [Next] - TBD
5+
## [1.1.0] - 2023-05-07
66

77
### Added
88

@@ -332,7 +332,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
332332

333333
**Initial release!**
334334

335-
[Next]: https://github.com/bakame-php/http-structured-fields/compare/1.0.1...master
335+
[Next]: https://github.com/bakame-php/http-structured-fields/compare/1.1.0...master
336+
[1.1.0]: https://github.com/bakame-php/http-structured-fields/compare/1.0.1...1.1.0
336337
[1.0.1]: https://github.com/bakame-php/http-structured-fields/compare/1.0.0...1.0.1
337338
[1.0.0]: https://github.com/bakame-php/http-structured-fields/compare/0.8.0...1.0.0
338339
[0.8.0]: https://github.com/bakame-php/http-structured-fields/compare/0.7.0...0.8.0

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ build and update HTTP Structured Fields in PHP according to the [RFC8941](https:
1313
Once installed you will be able to do the following:
1414

1515
```php
16-
use Bakame\Http\StructuredFields\InnerList;
17-
use Bakame\Http\StructuredFields\Item;
18-
use Bakame\Http\StructuredFields\OuterList;
19-
use Bakame\Http\StructuredFields\Token;
16+
use Bakame\Http\StructuredFields\{InnerList, Item, OuterList, Token};
2017

2118
//1 - parsing an Accept Header
2219
$headerValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';

src/InnerList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ final class InnerList implements MemberList, ParameterAccess
3737
*/
3838
private function __construct(iterable $members, private readonly Parameters $parameters)
3939
{
40-
$this->members = array_map(self::filterMember(...), array_values([...$members]));
40+
$this->members = array_map($this->filterMember(...), array_values([...$members]));
4141
}
4242

4343
/**
4444
* @param SfItemInput $member
4545
*
4646
* @return SfItem
4747
*/
48-
private static function filterMember(mixed $member): object
48+
private function filterMember(mixed $member): object
4949
{
5050
return match (true) {
5151
$member instanceof ValueAccess && $member instanceof ParameterAccess => $member,
@@ -285,7 +285,7 @@ public function remove(string|int ...$keys): static
285285

286286
return match (true) {
287287
[] === $indices => $this,
288-
$max === count($indices) => self::new(),
288+
count($indices) === $max => self::new(),
289289
default => new self(array_filter(
290290
$this->members,
291291
fn (int $key): bool => !in_array($key, $indices, true),

src/OuterList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ final class OuterList implements MemberList
3737
*/
3838
private function __construct(iterable|StructuredField|Token|ByteSequence|DateTimeInterface|string|int|float|bool ...$members)
3939
{
40-
$this->members = array_map(self::filterMember(...), array_values([...$members]));
40+
$this->members = array_map($this->filterMember(...), array_values([...$members]));
4141
}
4242

4343
/**
4444
* @param SfMember|SfMemberInput $member
4545
*
4646
* @return SfMember
4747
*/
48-
private static function filterMember(mixed $member): object
48+
private function filterMember(mixed $member): object
4949
{
5050
return match (true) {
5151
$member instanceof ParameterAccess && ($member instanceof MemberList || $member instanceof ValueAccess) => $member,

src/Parser.php

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ final class Parser implements DictionaryParser, InnerListParser, ItemParser, Lis
4646

4747
public function parseValue(Stringable|string $httpValue): ByteSequence|Token|DateTimeImmutable|string|int|float|bool
4848
{
49-
$valueString = trim((string) $httpValue, ' ');
50-
if ('' === $valueString || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $valueString)) {
51-
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item value contains invalid characters.');
49+
$remainder = trim((string) $httpValue, ' ');
50+
if ('' === $remainder || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $remainder)) {
51+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item value contains invalid characters.");
5252
}
5353

54-
[$value, $offset] = self::extractValue($valueString);
55-
if ('' !== substr($valueString, $offset)) {
56-
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item value contains invalid characters.');
54+
[$value, $offset] = self::extractValue($remainder);
55+
if ('' !== substr($remainder, $offset)) {
56+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item value contains invalid characters.");
5757
}
5858

5959
return $value;
@@ -64,15 +64,15 @@ public function parseValue(Stringable|string $httpValue): ByteSequence|Token|Dat
6464
*/
6565
public function parseItem(Stringable|string $httpValue): array
6666
{
67-
$itemString = trim((string) $httpValue, ' ');
68-
if ('' === $itemString || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $itemString)) {
69-
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
67+
$remainder = trim((string) $httpValue, ' ');
68+
if ('' === $remainder || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $remainder)) {
69+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item contains invalid characters.");
7070
}
7171

72-
[$value, $offset] = self::extractValue($itemString);
73-
$remainder = substr($itemString, $offset);
72+
[$value, $offset] = self::extractValue($remainder);
73+
$remainder = substr($remainder, $offset);
7474
if ('' !== $remainder && !str_contains($remainder, ';')) {
75-
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
75+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item contains invalid characters.");
7676
}
7777

7878
return [$value, $this->parseParameters($remainder)];
@@ -89,10 +89,10 @@ public function parseItem(Stringable|string $httpValue): array
8989
*/
9090
public function parseParameters(Stringable|string $httpValue): array
9191
{
92-
$parameterString = trim((string) $httpValue);
93-
[$parameters, $offset] = self::extractParametersValues($parameterString);
94-
if (strlen($parameterString) !== $offset) {
95-
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for Parameters contains invalid characters.');
92+
$remainder = trim((string) $httpValue);
93+
[$parameters, $offset] = self::extractParametersValues($remainder);
94+
if (strlen($remainder) !== $offset) {
95+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for Parameters contains invalid characters.");
9696
}
9797

9898
return $parameters;
@@ -170,23 +170,23 @@ public function parseInnerList(Stringable|string $httpValue): array
170170
*
171171
* @see https://tools.ietf.org/html/rfc7230#section-3.2.3
172172
*/
173-
private static function removeCommaSeparatedWhiteSpaces(string $httpValue, int $offset): string
173+
private static function removeCommaSeparatedWhiteSpaces(string $remainder, int $offset): string
174174
{
175-
$httpValue = self::removeOptionalWhiteSpaces(substr($httpValue, $offset));
176-
if ('' === $httpValue) {
177-
return $httpValue;
175+
$remainder = self::removeOptionalWhiteSpaces(substr($remainder, $offset));
176+
if ('' === $remainder) {
177+
return '';
178178
}
179179

180-
if (1 !== preg_match(self::REGEXP_VALID_SPACE, $httpValue, $found)) {
180+
if (1 !== preg_match(self::REGEXP_VALID_SPACE, $remainder, $found)) {
181181
throw new SyntaxError('The HTTP textual representation is missing an excepted comma.');
182182
}
183183

184-
$httpValue = substr($httpValue, strlen($found['space']));
185-
if ('' === $httpValue) {
184+
$remainder = substr($remainder, strlen($found['space']));
185+
if ('' === $remainder) {
186186
throw new SyntaxError('The HTTP textual representation has an unexpected end of line.');
187187
}
188188

189-
return $httpValue;
189+
return $remainder;
190190
}
191191

192192
/**
@@ -242,11 +242,11 @@ private static function extractInnerList(string $httpValue): array
242242
[$list[], $remainder] = self::extractItem($remainder);
243243

244244
if ('' !== $remainder && !in_array($remainder[0], [' ', ')'], true)) {
245-
throw new SyntaxError("The HTTP textual representation \"$remainder\" for a inner list is using invalid characters.");
245+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a inner list is using invalid characters.");
246246
}
247247
}
248248

249-
throw new SyntaxError("The HTTP textual representation \"$remainder\" for a inner list has an unexpected end of line.");
249+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a inner list has an unexpected end of line.");
250250
}
251251

252252
/**
@@ -372,41 +372,40 @@ private static function extractDate(string $httpValue): array
372372
private static function extractString(string $httpValue): array
373373
{
374374
$offset = 1;
375-
$originalHttpValue = $httpValue;
376-
$httpValue = substr($httpValue, $offset);
375+
$remainder = substr($httpValue, $offset);
377376
$output = '';
378377

379-
while ('' !== $httpValue) {
380-
$char = $httpValue[0];
378+
while ('' !== $remainder) {
379+
$char = $remainder[0];
381380
$offset += 1;
382381

383382
if ('"' === $char) {
384383
return [$output, $offset];
385384
}
386385

387386
if (1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $char)) {
388-
throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
387+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
389388
}
390389

391-
$httpValue = substr($httpValue, 1);
390+
$remainder = substr($remainder, 1);
392391

393392
if ('\\' !== $char) {
394393
$output .= $char;
395394
continue;
396395
}
397396

398-
$char = $httpValue[0] ?? '';
397+
$char = $remainder[0] ?? '';
399398
$offset += 1;
400-
$httpValue = substr($httpValue, 1);
399+
$remainder = substr($remainder, 1);
401400

402401
if (!in_array($char, ['"', '\\'], true)) {
403-
throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
402+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
404403
}
405404

406405
$output .= $char;
407406
}
408407

409-
throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
408+
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
410409
}
411410

412411
/**

0 commit comments

Comments
 (0)