1 | <?php |
||
11 | class Feed implements Responsable |
||
12 | { |
||
13 | /** @var string */ |
||
14 | protected $title; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $description; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $language; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $url; |
||
24 | |||
25 | /** @var string */ |
||
26 | protected $view; |
||
27 | |||
28 | /** @var \Illuminate\Support\Collection */ |
||
29 | protected $feedItems; |
||
30 | |||
31 | public function __construct( |
||
32 | string $title, |
||
33 | Collection $items, |
||
34 | string $url = '', |
||
35 | string $view = 'feed::feed', |
||
36 | string $description = '', |
||
37 | string $language = '' |
||
38 | ) { |
||
39 | $this->title = $title; |
||
40 | $this->description = $description; |
||
41 | $this->language = $language; |
||
42 | $this->url = $url ?? request()->url(); |
||
43 | $this->view = $view; |
||
44 | |||
45 | $this->feedItems = $items->map(function($feedable) { |
||
46 | return $this->castToFeedItem($feedable); |
||
47 | }); |
||
48 | } |
||
49 | |||
50 | public function toResponse($request): Response |
||
51 | { |
||
52 | $meta = [ |
||
53 | 'id' => url($this->url), |
||
54 | 'link' => url($this->url), |
||
55 | 'title' => $this->title, |
||
56 | 'description' => $this->description, |
||
57 | 'language' => $this->language, |
||
58 | 'updated' => $this->lastUpdated(), |
||
59 | ]; |
||
60 | |||
61 | $contents = view($this->view, [ |
||
62 | 'meta' => $meta, |
||
63 | 'items' => $this->feedItems, |
||
64 | ]); |
||
65 | |||
66 | return new Response($contents, 200, [ |
||
|
|||
67 | 'Content-Type' => 'application/xml;charset=UTF-8', |
||
68 | ]); |
||
69 | } |
||
70 | |||
71 | protected function castToFeedItem($feedable): FeedItem |
||
97 | |||
98 | protected function lastUpdated(): string |
||
99 | { |
||
108 | |||
109 | |||
110 | } |
||
111 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: