-
Notifications
You must be signed in to change notification settings - Fork 0
/
StopResponse.php
90 lines (79 loc) · 2.5 KB
/
StopResponse.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Mistrfilda\Pid\Api\Stop;
use Mistrfilda\Pid\Api\Http\Response\Response;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
class StopResponse extends Response
{
/** @var int */
private $count;
/** @var Stop[] */
private $stops = [];
public function getCount(): int
{
return $this->count;
}
/**
* @return Stop[]
*/
public function getStops(): array
{
return $this->stops;
}
/**
* @param array<mixed, mixed> $response
*/
protected function createFromArrayResponse(array $response): void
{
$count = 0;
foreach ($response['features'] as $stop) {
if ($stop['properties']['stop_name'] === null) {
continue;
}
$this->stops[] = new Stop(
$stop['properties']['stop_id'],
$stop['geometry']['coordinates'][1],
$stop['geometry']['coordinates'][0],
$stop['properties']['stop_name']
);
$count++;
}
$this->count = $count;
}
protected function getResponseSchema(): Schema
{
return Expect::structure([
'features' => Expect::arrayOf(Expect::structure([
'geometry' => Expect::structure([
'coordinates' => Expect::arrayOf(Expect::anyOf(Expect::int(), Expect::float()))->min(2)->max(2),
'type' => Expect::string(),
])->castTo('array'),
'properties' => Expect::structure([
'level_id' => Expect::string()->nullable(),
'location_type' => Expect::int()->nullable(),
'parent_station' => Expect::string()->nullable(),
'platform_code' => Expect::string()->nullable(),
'stop_code' => Expect::string()->nullable(),
'stop_desc' => Expect::string()->nullable(),
'stop_id' => Expect::string(),
'stop_lat' => Expect::anyOf(Expect::int(), Expect::float())->castTo('float'),
'stop_lon' => Expect::anyOf(Expect::int(), Expect::float())->castTo('float'),
'stop_name' => Expect::string()->nullable(),
'stop_timezone' => Expect::string()->nullable(),
'stop_url' => Expect::string()->nullable(),
'wheelchair_boarding' => Expect::int()->nullable(),
'zone_id' => Expect::string()->nullable(),
'create_batch_id' => Expect::string()->nullable(),
'created_at' => Expect::string()->nullable(),
'created_by' => Expect::string()->nullable(),
'update_batch_id' => Expect::string()->nullable(),
'updated_at' => Expect::string()->nullable(),
'updated_by' => Expect::string()->nullable(),
])->otherItems(Expect::mixed())->castTo('array'),
'type' => Expect::string(),
])->castTo('array')),
'type' => Expect::string(),
])->castTo('array');
}
}