1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Api\V1; |
4
|
|
|
|
5
|
|
|
use Nymfonya\Component\Container; |
6
|
|
|
use Nymfonya\Component\Http\Response; |
7
|
|
|
use App\Interfaces\Controllers\IApi; |
8
|
|
|
use App\Reuse\Controllers\AbstractApi; |
9
|
|
|
use App\Model\Repository\Metro\Lines; |
10
|
|
|
use App\Model\Repository\Metro\Stations; |
11
|
|
|
use App\Component\Db\Core; |
12
|
|
|
use App\Component\Model\Orm\Orm; |
13
|
|
|
|
14
|
|
|
final class Metro extends AbstractApi implements IApi |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Lines model |
18
|
|
|
* |
19
|
|
|
* @var Lines |
20
|
|
|
*/ |
21
|
|
|
protected $modelLines; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Stations model |
26
|
|
|
* |
27
|
|
|
* @var Stations |
28
|
|
|
*/ |
29
|
|
|
protected $modelStations; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* db core |
33
|
|
|
* |
34
|
|
|
* @var Core |
35
|
|
|
*/ |
36
|
|
|
protected $dbCore; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* instanciate |
40
|
|
|
* |
41
|
|
|
* @param Container $container |
42
|
|
|
*/ |
43
|
4 |
|
public function __construct(Container $container) |
44
|
|
|
{ |
45
|
4 |
|
parent::__construct($container); |
46
|
4 |
|
$this->modelLines = new Lines($container); |
47
|
4 |
|
$this->modelStations = new Stations($container); |
48
|
4 |
|
$this->dbCore = new Core($container); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* search lines |
53
|
|
|
* |
54
|
|
|
* @return Metro |
55
|
|
|
*/ |
56
|
1 |
|
final public function lines(): Metro |
57
|
|
|
{ |
58
|
1 |
|
$this->response->setCode(Response::HTTP_OK)->setContent([ |
59
|
1 |
|
Response::_ERROR => false, |
60
|
1 |
|
Response::_ERROR_MSG => '', |
61
|
1 |
|
'datas' => $this->getQueryResults( |
62
|
1 |
|
$this->modelLines->find(['*'], []) |
63
|
|
|
) |
64
|
|
|
]); |
65
|
1 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* search stations |
70
|
|
|
* |
71
|
|
|
* @return Metro |
72
|
|
|
*/ |
73
|
1 |
|
final public function stations(): Metro |
74
|
|
|
{ |
75
|
1 |
|
$this->response->setCode(Response::HTTP_OK)->setContent([ |
76
|
1 |
|
Response::_ERROR => false, |
77
|
1 |
|
Response::_ERROR_MSG => '', |
78
|
1 |
|
'datas' => $this->getQueryResults( |
79
|
1 |
|
$this->modelStations->find(['*'], []) |
80
|
|
|
) |
81
|
|
|
]); |
82
|
1 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* get query results |
87
|
|
|
* |
88
|
|
|
* @param Orm $query |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
1 |
|
protected function getQueryResults(Orm $query) |
92
|
|
|
{ |
93
|
1 |
|
return $this->dbCore->fromOrm($query)->run( |
94
|
1 |
|
$query->getSql(), |
95
|
1 |
|
$query->getBuilderValues() |
96
|
1 |
|
)->hydrate() |
97
|
1 |
|
->getRowset(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|