-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems.php
123 lines (117 loc) · 4.24 KB
/
items.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
function delay($max_ms){
usleep(rand(0,$max_ms*1000));
}
//Читаем строку потока
if($stdin_line = fgets(STDIN)) {
error_log($stdin_line);
$arOutput = json_decode($stdin_line, TRUE);
$cls = $arOutput["class"];
error_log("Class: " . $cls);
$res = "";
if(preg_match('#^normal#', $cls) === 1){
$res = json_encode(
Array("items" => Array(
Array(
"code" => "3311",
"brand"=> "ctr",
"name"=> "Товар1",
"price"=> "123",
"quantity"=> "30"
),
Array(
"code"=> "3302",
"brand"=> "bermo",
"name"=> "Товар2",
"price"=> "120",
"quantity"=> "10"
),
Array(
"code"=> "3333",
"brand"=> "kama",
"name"=> "Товар3",
"price"=> "200",
"quantity"=> "4"
)
)
)
);
} else if(preg_match('#^analog#', $cls) === 1) {
$res = json_encode(
Array("items" => Array(
Array(
"code" => "3311",
"brand"=> "ctr",
"name"=> "Товар1",
"price"=> "123",
"quantity"=> "30"
),
Array(
"code"=> "3302",
"brand"=> "bermo",
"name"=> "Товар2",
"price"=> "120",
"quantity"=> "10"
),
Array(
"code"=> "3333",
"brand"=> "kama",
"name"=> "Товар3",
"price"=> "200",
"quantity"=> "4"
)
),
"suppliers"=> Array(
Array(
"class"=> "normal-1",
"params"=> Array(
"login"=> "log1234",
"password"=> "1234"
),
"code"=> "3310",
"brand"=> "ctr",
"analog"=> "1",
"info"=> Array(
"foo" => 1,
"bar" => 2
)
),
Array(
"class"=> "normal-2",
"params"=> Array(
"login"=> "log1234",
"password"=> "1234",
"domain"=> "msk"
),
"code"=> "3310",
"brand"=> "ctr",
"analog"=> "1",
"info"=> Array(
"foo" => 1,
"bar" => 2
)
)
)
)
);
} else if(preg_match('#^empty#', $cls) === 1) {
$res = json_encode(
Array(
"items" => Array(
)
)
);
} else if(preg_match('#^badjson#', $cls) === 1) {
$res = "Not a Json response";
} else if(preg_match('#^timeout#', $cls) === 1) {
sleep(60);
} else if(preg_match('#^error#', $cls) === 1) {
exit(-1);
} else {
error_log("Unrecognized Item class");
exit(-1);
}
fwrite(STDOUT, $res);
delay(1000);
}
?>