-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.php
37 lines (30 loc) · 1.14 KB
/
Reader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace myApp;
class Reader implements ReaderInterface
{
/**
* @inheritDoc
*/
public function read(string $input): OfferCollectionInterface
{
$returnCollection = [];
$data = json_decode($input);
if (!$data) {
echo json_encode(["error" => "couldn't decode offers!"]);
if (isset($_SERVER["REQUEST_METHOD"])) {
$file = fopen('./logs/' . date('Y-m-d'), "a");
fwrite($file, "Request Failed: couldn't decode offers! api response was: \n $input \n\n-----------------\n\n");
fclose($file);
} else {
$file = fopen('./logs/' . date('Y-m-d') . "-CLI", "a");
fwrite($file, "CLI call Failed: couldn't decode offers! api response was: \n $input \n\n-----------------\n\n");
fclose($file);
}
die();
}
foreach ($data as $offer) {
$returnCollection[] = new Offer($offer->offerId, $offer->productTitle, $offer->vendorId, $offer->price);
}
return new OfferCollection($returnCollection);
}
}