Skip to content

Commit 218dc9e

Browse files
committed
Все методы api теперь возращают json
1 parent 4f145db commit 218dc9e

File tree

11 files changed

+207
-35
lines changed

11 files changed

+207
-35
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
"ext-json": "*",
1717
"ext-curl": "*",
1818
"ext-mbstring": "*",
19-
"guzzlehttp/guzzle": "^7.4"
19+
"guzzlehttp/guzzle": "^7.7"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^9.5"
22+
"phpunit/phpunit": "^9.5",
23+
"symfony/var-dumper": "^6.0"
2324
},
2425
"autoload": {
2526
"psr-4": {

composer.lock

Lines changed: 172 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/station_code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$stations = $api->stationCode($params);
1212

1313
if ($stations) {
14-
var_dump($stations);
14+
echo $stations;
1515
} else {
1616
echo 'Не найдено совпадений!';
1717
}

examples/train_carriages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'code1' => '2000000',
1616
'dt0' => $date0->format('d.m.Y'),
1717
];
18-
$routes = $api->trainRoutes($params);
18+
$routes = json_decode($api->trainRoutes($params));
1919

2020
if ($routes) {
2121
$params = [
@@ -27,7 +27,7 @@
2727
'tnum0' => $routes[0]->number,
2828
];
2929

30-
var_dump($api->trainCarriages($params));
30+
echo $api->trainCarriages($params);
3131

3232
} else {
3333
echo 'Не удалось найти маршрут';

examples/train_routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
$api = new Rzd\Api();
1818

19-
var_dump($api->trainRoutes($params));
19+
echo $api->trainRoutes($params);

examples/train_routes_params.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$config->setReferer('https://ticket.rzd.ru/');
1515

1616
// Enable debug mode
17-
$config->setDebugMode(true);
17+
//$config->setDebugMode(true);
1818

1919
// Enable proxy
2020
//$config->setProxy('https://username:password@192.168.16.1:10');
@@ -33,4 +33,4 @@
3333

3434
$api = new Rzd\Api($config);
3535

36-
var_dump($api->trainRoutes($params));
36+
echo $api->trainRoutes($params);

examples/train_routes_return.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
$api = new Rzd\Api();
2020

21-
var_dump($api->trainRoutesReturn($params));
21+
echo $api->trainRoutesReturn($params);

examples/train_routes_transfer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
$api = new Rzd\Api();
1919

20-
var_dump($api->trainRoutes($params));
20+
echo $api->trainRoutes($params);

examples/train_station_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
'depDate' => $date0->format('d.m.Y'),
1212
];
1313

14-
var_dump($api->trainStationList($params));
14+
echo $api->trainStationList($params);

src/Rzd/Api.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class Api
88
{
99
public const ROUTES_LAYER = 5827;
1010
public const CARRIAGES_LAYER = 5764;
11-
1211
public const STATIONS_STRUCTURE_ID = 704;
1312

1413
/**
@@ -50,93 +49,93 @@ public function __construct(Config $config = null)
5049
*
5150
* @param array $params Массив параметров
5251
*
53-
* @return array<object>
52+
* @return string
5453
* @throws GuzzleException
5554
*/
56-
public function trainRoutes(array $params): array
55+
public function trainRoutes(array $params): string
5756
{
5857
$layer = [
5958
'layer_id' => static::ROUTES_LAYER,
6059
];
6160
$routes = $this->query->get($this->path, $layer + $params);
6261

63-
return $routes->tp[0]->list;
62+
return json_encode($routes->tp[0]->list, JSON_UNESCAPED_UNICODE);
6463
}
6564

6665
/**
6766
* Получает маршруты туда-обратно
6867
*
6968
* @param array $params Массив параметров
7069
*
71-
* @return array<object>
70+
* @return string
7271
* @throws GuzzleException
7372
*/
74-
public function trainRoutesReturn(array $params): array
73+
public function trainRoutesReturn(array $params): string
7574
{
7675
$layer = [
7776
'layer_id' => static::ROUTES_LAYER,
7877
];
7978
$routes = $this->query->get($this->path, $layer + $params);
8079

81-
return [
80+
return json_encode([
8281
'forward' => $routes->tp[0]->list,
8382
'back' => $routes->tp[1]->list
84-
];
83+
], JSON_UNESCAPED_UNICODE);
8584
}
8685

8786
/**
8887
* Получение списка вагонов
8988
*
9089
* @param array $params Массив параметров
9190
*
92-
* @return array<object>
91+
* @return string
9392
* @throws GuzzleException
9493
*/
95-
public function trainCarriages(array $params): array
94+
public function trainCarriages(array $params): string
9695
{
9796
$layer = [
9897
'layer_id' => static::CARRIAGES_LAYER,
9998
];
10099
$carriages = $this->query->get($this->path, $layer + $params);
101100

102-
return [
101+
return json_encode([
103102
'cars' => $carriages->lst[0]->cars ?? null,
104103
'functionBlocks' => $carriages->lst[0]->functionBlocks ?? null,
105104
'schemes' => $carriages->schemes ?? null,
106105
'companies' => $carriages->insuranceCompany ?? null,
107-
];
106+
], JSON_UNESCAPED_UNICODE);
108107
}
109108

110109
/**
111110
* Получение списка станций
112111
*
113112
* @param array $params Массив параметров
114113
*
115-
* @return array
114+
* @return string
116115
* @throws GuzzleException
117116
*/
118-
public function trainStationList(array $params): array
117+
public function trainStationList(array $params): string
119118
{
120119
$layer = [
121120
'STRUCTURE_ID' => static::STATIONS_STRUCTURE_ID,
122121
];
123122
$stations = $this->query->get($this->stationListPath, $layer + $params);
124123

125-
return [
124+
return json_encode([
126125
'train' => $stations->data->trainInfo,
127126
'routes' => $stations->data->routes,
128-
];
127+
], JSON_UNESCAPED_UNICODE);
129128
}
130129

131130
/**
132131
* Получение списка кодов станций
133132
*
134133
* @param array $params Массив параметров
135134
*
136-
* @return array
135+
* @return string
137136
* @throws GuzzleException
138137
*/
139-
public function stationCode(array $params): array
138+
public function stationCode(array $params): string
140139
{
141140
$lang = [
142141
'lang' => $this->lang,
@@ -156,6 +155,6 @@ public function stationCode(array $params): array
156155
}
157156
}
158157

159-
return $stations;
158+
return json_encode($stations, JSON_UNESCAPED_UNICODE);
160159
}
161160
}

0 commit comments

Comments
 (0)