/
Company.php
46 lines (36 loc) · 1006 Bytes
/
Company.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
38
39
40
41
42
43
44
45
46
<?php
namespace GOAPI\IO\Resources\Stock;
use Psr\Http\Message\ResponseInterface;
class Company {
public $symbol;
public $name;
public $logo;
function __construct(
$symbol,
$name,
$logo
)
{
$this->symbol = $symbol;
$this->name = $name;
$this->logo = $logo;
}
static function fromArray($array): Company {
return new self(
$array['symbol'],
$array['name'],
$array['logo']
);
}
static function fromArrayList($array): \GOAPI\IO\Collection {
$output = [];
foreach($array as $item) {
$output[] = new static($item->symbol, $item->name, $item->logo);
}
return new \GOAPI\IO\Collection($output);
}
static function fromResponse(ResponseInterface $response): \GOAPI\IO\Collection {
$array = json_decode($response->getBody()->getContents());
return self::fromArrayList($array->data->results);
}
}