Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit acc78bf

Browse files
authored
Merge pull request #24 from sunrise-php/release/v2.1.0
v2.1.0
2 parents 7be6b5d + 143d1b1 commit acc78bf

20 files changed

+241
-37
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
## Installation
1313

1414
```bash
15-
composer require 'sunrise/http-header-kit:^2.0'
15+
composer require 'sunrise/http-header-kit:^2.1'
1616
```
1717

1818
## How to use?
@@ -39,6 +39,20 @@ $response->header(...$header);
3939

4040
> ⚠️ Note that in the examples below will use PSR-7.
4141
42+
#### Custom header
43+
44+
> Use this header if you can't find a suitable one below.
45+
46+
```php
47+
use Sunrise\Http\Header\HeaderCustom;
48+
use Sunrise\Http\Message\ResponseFactory;
49+
50+
$header = new HeaderCustom('X-Fiend-Name', 'field-value');
51+
52+
(new ResponseFactory) ->createResponse()
53+
->withHeader(...$header);
54+
```
55+
4256
#### Access-Control-Allow-Credentials
4357

4458
> Usage link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials

src/AbstractHeader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
/**
2727
* AbstractHeader
28+
*
29+
* @template-implements IteratorAggregate<int, string>
2830
*/
2931
abstract class AbstractHeader implements HeaderInterface, IteratorAggregate
3032
{

src/HeaderAccessControlAllowHeaders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function setValue(string ...$value) : self
7878
/**
7979
* Gets the header value
8080
*
81-
* @return array<int, string>
81+
* @return list<string>
8282
*/
8383
public function getValue() : array
8484
{

src/HeaderAccessControlAllowMethods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function setValue(string ...$value) : self
8181
/**
8282
* Gets the header value
8383
*
84-
* @return array<int, string>
84+
* @return list<string>
8585
*/
8686
public function getValue() : array
8787
{

src/HeaderAccessControlAllowOrigin.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ public function getFieldValue() : string
9999
return '*';
100100
}
101101

102-
$value = $uri->getScheme() . '://' . $uri->getHost();
103-
if (null !== $uri->getPort()) {
104-
$value .= ':' . $uri->getPort();
102+
$value = $uri->getScheme() . ':';
103+
$value .= '//' . $uri->getHost();
104+
105+
$port = $uri->getPort();
106+
if (null !== $port) {
107+
$value .= ':' . $port;
105108
}
106109

107110
return $value;

src/HeaderAccessControlExposeHeaders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function setValue(string ...$value) : self
7878
/**
7979
* Gets the header value
8080
*
81-
* @return array<string>
81+
* @return list<string>
8282
*/
8383
public function getValue() : array
8484
{

src/HeaderAllow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function setValue(string ...$value) : self
8181
/**
8282
* Gets the header value
8383
*
84-
* @return array<int, string>
84+
* @return list<string>
8585
*/
8686
public function getValue() : array
8787
{

src/HeaderClearSiteData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function setValue(string ...$value) : self
7878
/**
7979
* Gets the header value
8080
*
81-
* @return array<int, string>
81+
* @return list<string>
8282
*/
8383
public function getValue() : array
8484
{

src/HeaderContentLanguage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function setValue(string ...$value) : self
8787
/**
8888
* Gets the header value
8989
*
90-
* @return array<int, string>
90+
* @return list<string>
9191
*/
9292
public function getValue() : array
9393
{

src/HeaderCustom.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* It's free open-source software released under the MIT License.
5+
*
6+
* @author Anatoly Fenric <anatoly@fenric.ru>
7+
* @copyright Copyright (c) 2018, Anatoly Fenric
8+
* @license https://github.com/sunrise-php/http-header-kit/blob/master/LICENSE
9+
* @link https://github.com/sunrise-php/http-header-kit
10+
*/
11+
12+
namespace Sunrise\Http\Header;
13+
14+
/**
15+
* Import classes
16+
*/
17+
use InvalidArgumentException;
18+
19+
/**
20+
* HeaderCustom
21+
*/
22+
class HeaderCustom extends AbstractHeader implements HeaderInterface
23+
{
24+
25+
/**
26+
* The header name
27+
*
28+
* @var string
29+
*/
30+
protected $fieldName;
31+
32+
/**
33+
* The header value
34+
*
35+
* @var string
36+
*/
37+
protected $fieldValue;
38+
39+
/**
40+
* Constructor of the class
41+
*
42+
* @param string $fieldName
43+
* @param string $fieldValue
44+
*
45+
* @throws InvalidArgumentException
46+
* If the name or value isn't valid.
47+
*/
48+
public function __construct(string $fieldName, string $fieldValue)
49+
{
50+
if (!preg_match(HeaderInterface::RFC7230_TOKEN, $fieldName)) {
51+
throw new InvalidArgumentException(sprintf('Name of the header "%s" is not valid', $fieldName));
52+
}
53+
54+
if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $fieldValue)) {
55+
throw new InvalidArgumentException(sprintf('Value of the header "%s" is not valid', $fieldName));
56+
}
57+
58+
$this->fieldName = $fieldName;
59+
$this->fieldValue = $fieldValue;
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function getFieldName() : string
66+
{
67+
return $this->fieldName;
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function getFieldValue() : string
74+
{
75+
return $this->fieldValue;
76+
}
77+
}

0 commit comments

Comments
 (0)