File tree Expand file tree Collapse file tree 2 files changed +8
-18
lines changed
Expand file tree Collapse file tree 2 files changed +8
-18
lines changed Original file line number Diff line number Diff line change 1111
1212class 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 ) {
Original file line number Diff line number Diff line change 55namespace FeedIo ;
66
77use DateTime ;
8- use FeedIo \Adapter \ClientInterface ;
9- use FeedIo \Adapter \NullClient ;
8+ use FeedIo \Adapter \Client ;
109use FeedIo \Http \ResponseBuilder ;
1110use FeedIo \Reader \Result ;
1211use FeedIo \Rule \DateTimeBuilderInterface ;
12+ use Psr \Http \Client \ClientInterface ;
1313use Psr \Http \Message \ResponseInterface ;
1414use Psr \Log \LoggerInterface ;
1515use 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 }
You can’t perform that action at this time.
0 commit comments