forked from zeroc-ice/ice-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
185 lines (159 loc) · 4.48 KB
/
Client.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
//
// Enable error reporting
//
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once 'Ice.php';
require_once 'Contact.php';
$communicator = Ice\initialize();
try
{
$base = $communicator->stringToProxy("contactdb:default -h localhost -p 10000");
$contactdb = Demo\ContactDBPrxHelper::checkedCast($base);
//
// Add a contact for "john". All parameters are provided.
//
$johnNumber = "123-456-7890";
$contactdb->addContact("john", Demo\NumberType::HOME, $johnNumber, 0);
echo "Checking john... ";
//
// Find the phone number for "john"
//
$number = $contactdb->queryNumber("john");
if($number != $johnNumber)
{
echo "number is incorrect ";
}
// Optional can also be used in an out parameter.
$dialgroup = Ice\None;
$contactdb->queryDialgroup("john", $dialgroup);
if($dialgroup != 0)
{
echo "dialgroup is incorrect ";
}
$info = $contactdb->query("john");
//
// All of the info parameters should be set.
//
if($info->type != Demo\NumberType::HOME || $info->number != $johnNumber || $info->dialGroup != 0)
{
echo "info is incorrect ";
}
echo "ok\n";
//
// Add a contact for "steve". The behavior of the server is to
// default construct the Contact, and then assign all set parameters.
// Since the default value of NumberType in the slice definition
// is HOME and in this case the NumberType is unset it will take
// the default value.
//
$steveNumber = "234-567-8901";
$contactdb->addContact("steve", Ice\None, $steveNumber, 1);
echo "Checking steve... ";
$number = $contactdb->queryNumber("steve");
if($number != $steveNumber)
{
echo "number is incorrect ";
}
$info = $contactdb->query("steve");
//
// Check the value for the NumberType.
//
if($info->type != Demo\NumberType::HOME)
{
echo "info is incorrect ";
}
if($info->number != $steveNumber || $info->dialGroup != 1)
{
echo "info is incorrect ";
}
$contactdb->queryDialgroup("steve", $dialgroup);
if($dialgroup != 1)
{
echo "dialgroup is incorrect ";
}
echo "ok\n";
//
// Add a contact from "frank". Here the dialGroup field isn't set.
//
$frankNumber = "345-678-9012";
$contactdb->addContact("frank", Demo\NumberType::CELL, $frankNumber, Ice\None);
echo "Checking frank... ";
$number = $contactdb->queryNumber("frank");
if($number != $frankNumber)
{
echo "number is incorrect ";
}
$info = $contactdb->query("frank");
//
// The dial group field should be unset.
//
if($info->dialGroup != Ice\None)
{
echo "info is incorrect ";
}
if($info->type != Demo\NumberType::CELL || $info->number != $frankNumber)
{
echo "info is incorrect ";
}
$contactdb->queryDialgroup("frank", $dialgroup);
if($dialgroup != Ice\None)
{
echo "dialgroup is incorrect ";
}
echo "ok\n";
//
// Add a contact from "anne". The number field isn't set.
//
$contactdb->addContact("anne", Demo\NumberType::OFFICE, Ice\None, 2);
echo "Checking anne... ";
$number = $contactdb->queryNumber("anne");
if($number != Ice\None)
{
echo "number is incorrect ";
}
$info = $contactdb->query("anne");
//
// The number field should be unset.
//
if($info->number != Ice\None)
{
echo "info is incorrect ";
}
if($info->type != Demo\NumberType::OFFICE || $info->dialGroup != 2)
{
echo "info is incorrect ";
}
$contactdb->queryDialgroup("anne", $dialgroup);
if($dialgroup != 2)
{
echo "dialgroup is incorrect ";
}
//
// The optional fields can be used to determine what fields to
// update on the contact. Here we update only the number for anne,
// the remainder of the fields are unchanged.
//
$anneNumber = "456-789-0123";
$contactdb->updateContact("anne", Ice\None, $anneNumber, Ice\None);
$number = $contactdb->queryNumber("anne");
if($number != $anneNumber)
{
echo "number is incorrect ";
}
$info = $contactdb->query("anne");
if($info->number != $anneNumber || $info->type != Demo\NumberType::OFFICE || $info->dialGroup != 2)
{
echo "info is incorrect ";
}
echo "ok\n";
$contactdb->shutdown();
}
catch(\Ice\LocalException $ex)
{
print_r($ex);
}
?>