Skip to content

Commit 4c806c7

Browse files
committed
Merge branch 'psr-7'
2 parents 350304a + 32172cc commit 4c806c7

28 files changed

+1075
-132
lines changed

src/Curler/Contract/ICurlerPage.php

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

33
namespace Lkrms\Curler\Contract;
44

5-
use Lkrms\Http\Contract\IHttpHeaders;
5+
use Lkrms\Http\Contract\HttpHeadersInterface;
66

77
interface ICurlerPage
88
{
@@ -42,5 +42,5 @@ public function nextData(): ?array;
4242
*
4343
* Return `null` to use the same headers sent with the last request.
4444
*/
45-
public function nextHeaders(): ?IHttpHeaders;
45+
public function nextHeaders(): ?HttpHeadersInterface;
4646
}

src/Curler/Curler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Lkrms\Http\Catalog\HttpHeader;
2323
use Lkrms\Http\Catalog\HttpHeaderGroup;
2424
use Lkrms\Http\Catalog\HttpRequestMethod;
25-
use Lkrms\Http\Contract\IHttpHeaders;
25+
use Lkrms\Http\Contract\HttpHeadersInterface;
2626
use Lkrms\Http\HttpHeaders;
2727
use Lkrms\Iterator\RecursiveCallbackIterator;
2828
use Lkrms\Iterator\RecursiveMutableGraphIterator;
@@ -44,13 +44,13 @@
4444
* A (very) lightweight Guzzle alternative.
4545
*
4646
* @property-read string $BaseUrl Resource URL (no query or fragment)
47-
* @property-read IHttpHeaders $Headers Request headers
47+
* @property-read HttpHeadersInterface $Headers Request headers
4848
* @property-read string|null $Method Most recent request method
4949
* @property-read string|null $QueryString Query string most recently added to request URL
5050
* @property-read string|mixed[]|null $Body Request body, as passed to cURL
5151
* @property-read string|mixed[]|object|null $Data Request body, before serialization
5252
* @property-read ICurlerPager|null $Pager Pagination handler
53-
* @property-read IHttpHeaders|null $ResponseHeaders Response headers
53+
* @property-read HttpHeadersInterface|null $ResponseHeaders Response headers
5454
* @property-read array<string,string>|null $ResponseHeadersByName An array that maps lowercase response headers to their combined values
5555
* @property-read int|null $StatusCode Response status code
5656
* @property-read string|null $ReasonPhrase Response status explanation
@@ -98,7 +98,7 @@ final class Curler implements IReadable, IWritable, Buildable
9898
/**
9999
* Request headers
100100
*
101-
* @var IHttpHeaders
101+
* @var HttpHeadersInterface
102102
*/
103103
protected $Headers;
104104

@@ -143,7 +143,7 @@ final class Curler implements IReadable, IWritable, Buildable
143143
/**
144144
* Response headers
145145
*
146-
* @var IHttpHeaders|null
146+
* @var HttpHeadersInterface|null
147147
*/
148148
protected $ResponseHeaders;
149149

@@ -441,7 +441,7 @@ final class Curler implements IReadable, IWritable, Buildable
441441
*/
442442
public function __construct(
443443
string $baseUrl,
444-
?IHttpHeaders $headers = null,
444+
?HttpHeadersInterface $headers = null,
445445
?ICurlerPager $pager = null,
446446
bool $cacheResponse = false,
447447
bool $cachePostResponse = false,
@@ -562,7 +562,7 @@ public function setContentType(?string $mimeType)
562562
*
563563
* @return $this
564564
*/
565-
public function withHeaders(IHttpHeaders $headers)
565+
public function withHeaders(HttpHeadersInterface $headers)
566566
{
567567
$clone = $this->clone();
568568
$clone->Headers = $headers;
@@ -1073,7 +1073,7 @@ private function getCacheKey(): ?string
10731073
/**
10741074
* @param mixed[]|null $query
10751075
*/
1076-
public function head(?array $query = null): IHttpHeaders
1076+
public function head(?array $query = null): HttpHeadersInterface
10771077
{
10781078
return $this->process(HttpRequestMethod::HEAD, $query);
10791079
}

src/Curler/CurlerBuilder.php

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Curler/Pager/ODataPager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function prepareCurler(Curler $curler): Curler
4646
if ($this->MaxPageSize === null) {
4747
return $curler;
4848
}
49-
/** @todo implement `Prefer` header wrangling in `IHttpHeaders`? */
49+
/** @todo wrangle `Prefer` headers in `HttpHeadersInterface`? */
5050
$preference = sprintf('odata.maxpagesize=%d', $this->MaxPageSize);
5151
$value = $curler->Headers->getHeader(HttpHeader::PREFER);
5252
$pattern = '/^odata\.maxpagesize\h*=/i';

src/Curler/Support/CurlerPage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Lkrms\Curler\Contract\ICurlerPage;
66
use Lkrms\Curler\Curler;
77
use Lkrms\Exception\AssertionFailedException;
8-
use Lkrms\Http\Contract\IHttpHeaders;
8+
use Lkrms\Http\Contract\HttpHeadersInterface;
99

1010
/**
1111
* Implements ICurlerPage
@@ -38,7 +38,7 @@ final class CurlerPage implements ICurlerPage
3838
private $NextData;
3939

4040
/**
41-
* @var IHttpHeaders|null
41+
* @var HttpHeadersInterface|null
4242
*/
4343
private $NextHeaders;
4444

@@ -48,7 +48,7 @@ final class CurlerPage implements ICurlerPage
4848
* @param null|string $nextUrl The URL of the next page, including the query component (if any)
4949
* @param null|bool $isLastPage Set if no more data is available
5050
* @param null|mixed[] $nextData Data to send in the body of the next request
51-
* @param null|IHttpHeaders $nextHeaders Replaces the next request's HTTP headers
51+
* @param null|HttpHeadersInterface $nextHeaders Replaces the next request's HTTP headers
5252
*/
5353
public function __construct(
5454
array $entities,
@@ -57,7 +57,7 @@ public function __construct(
5757
?string $nextUrl = null,
5858
?bool $isLastPage = null,
5959
?array $nextData = null,
60-
?IHttpHeaders $nextHeaders = null
60+
?HttpHeadersInterface $nextHeaders = null
6161
) {
6262
$this->Entities = $entities;
6363
$this->EntityCount = count($entities) + ($previous ? $previous->entityCount() : 0);
@@ -106,7 +106,7 @@ final public function nextData(): ?array
106106
return $this->NextData;
107107
}
108108

109-
final public function nextHeaders(): ?IHttpHeaders
109+
final public function nextHeaders(): ?HttpHeadersInterface
110110
{
111111
$this->assertHasNextPage();
112112

src/Curler/Support/CurlerPageBuilder.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Exception;
4+
5+
use Lkrms\Utility\Get;
6+
7+
/**
8+
* Thrown when a function receives an argument that is not of the required type
9+
*/
10+
class InvalidArgumentTypeException extends \Lkrms\Exception\InvalidArgumentException
11+
{
12+
/**
13+
* @param int $position The argument number (1-based).
14+
* @param string $name The name of the argument.
15+
* @param string $type The expected type.
16+
* @param mixed $value The value given.
17+
*/
18+
public function __construct(int $position, string $name, string $type, $value)
19+
{
20+
parent::__construct(sprintf(
21+
'Argument #%d ($%s) must be of type %s, %s given',
22+
$position,
23+
ltrim($name, '$'),
24+
$type,
25+
Get::type($value)
26+
));
27+
}
28+
}

src/Http/Contract/IAccessToken.php renamed to src/Http/Contract/AccessTokenInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Lkrms\Http\Contract;
44

5-
interface IAccessToken
5+
interface AccessTokenInterface
66
{
77
/**
88
* Get the object's token string

src/Http/Contract/IHttpHeaders.php renamed to src/Http/Contract/HttpHeadersInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
use Lkrms\Contract\Arrayable;
66
use Lkrms\Contract\ICollection;
7-
use Lkrms\Contract\IImmutable;
87
use Lkrms\Http\Catalog\HttpHeader;
98

109
/**
1110
* A collection of HTTP headers
1211
*
1312
* @extends ICollection<string,string[]>
1413
*/
15-
interface IHttpHeaders extends ICollection, IImmutable
14+
interface HttpHeadersInterface extends ICollection
1615
{
1716
/**
1817
* Parse and apply an HTTP header field or continuation thereof
1918
*
2019
* This method should be called once per HTTP header line. Each line must
2120
* have a trailing CRLF. If an empty line (`"\r\n"`) is given, subsequent
22-
* headers applied via {@see IHttpHeaders::addLine()} are flagged as
23-
* trailers. Aside from {@see IHttpHeaders::trailers()} and
24-
* {@see IHttpHeaders::withoutTrailers()}, {@see IHttpHeaders} methods make
25-
* no distinction between trailers and other headers.
21+
* headers applied via {@see HttpHeadersInterface::addLine()} are flagged as
22+
* trailers. Aside from {@see HttpHeadersInterface::trailers()} and
23+
* {@see HttpHeadersInterface::withoutTrailers()},
24+
* {@see HttpHeadersInterface} methods make no distinction between trailers
25+
* and other headers.
2626
*
2727
* @param bool $strict If `true`, throw an exception if `$line` is not
2828
* \[RFC7230]-compliant.
@@ -65,7 +65,7 @@ public function merge($items, bool $preserveExisting = false);
6565
* @return static
6666
*/
6767
public function authorize(
68-
IAccessToken $token,
68+
AccessTokenInterface $token,
6969
string $headerName = HttpHeader::AUTHORIZATION
7070
);
7171

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Http\Exception;
4+
5+
/**
6+
* Thrown when a stream wrapper receives a request it cannot service because it
7+
* has been detached from the underlying PHP stream
8+
*/
9+
class StreamDetachedException extends \Lkrms\Exception\Exception {}

0 commit comments

Comments
 (0)