Skip to content

Commit 6278a86

Browse files
committed
Pass PSR-18 compliant HTTP client to FeedIo facade
1 parent 1dff2b5 commit 6278a86

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/FeedIo/Adapter/Client.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,10 @@
1111

1212
class Client implements ClientInterface
1313
{
14-
public const DEFAULT_USER_AGENT = 'Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1';
15-
16-
public function __construct(private PsrClientInterface $client, private string $userAgent = self::DEFAULT_USER_AGENT)
14+
public function __construct(private PsrClientInterface $client)
1715
{
1816
}
1917

20-
/**
21-
* @param string $userAgent The new user-agent
22-
* @return self
23-
*/
24-
public function setUserAgent(string $userAgent): Client
25-
{
26-
$this->userAgent = $userAgent;
27-
28-
return $this;
29-
}
30-
3118
/**
3219
* @param string $url
3320
* @param DateTime|null $modifiedSince
@@ -81,7 +68,6 @@ protected function getHeaders(DateTime $modifiedSince = null): array
8168
{
8269
$headers = [
8370
'Accept-Encoding' => 'gzip, deflate',
84-
'User-Agent' => $this->userAgent,
8571
];
8672

8773
if ($modifiedSince) {

src/FeedIo/FeedIo.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace FeedIo;
66

77
use DateTime;
8-
use FeedIo\Adapter\ClientInterface;
9-
use FeedIo\Adapter\NullClient;
8+
use FeedIo\Adapter\Client;
109
use FeedIo\Http\ResponseBuilder;
1110
use FeedIo\Reader\Result;
1211
use FeedIo\Rule\DateTimeBuilderInterface;
12+
use Psr\Http\Client\ClientInterface;
1313
use Psr\Http\Message\ResponseInterface;
1414
use Psr\Log\LoggerInterface;
1515
use Psr\Log\NullLogger;
@@ -67,10 +67,14 @@ class FeedIo
6767
protected Reader $reader;
6868

6969
public function __construct(
70-
protected ClientInterface $client = new NullClient(),
70+
?ClientInterface $client = null,
7171
protected LoggerInterface $logger = new NullLogger(),
7272
protected ?SpecificationInterface $specification = null,
7373
) {
74+
if (is_null($client)) {
75+
throw new \Exception('You must provide a PSR18-compliant HTTP client');
76+
}
77+
$this->client = new Client($client);
7478
if (is_null($this->specification)) {
7579
$this->specification = new Specification($this->logger);
7680
}

0 commit comments

Comments
 (0)