Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
#!/usr/bin/env php
2
<?php
3
/*
4
 * Licensed to the Apache Software Foundation (ASF) under one
5
 * or more contributor license agreements. See the NOTICE file
6
 * distributed with this work for additional information
7
 * regarding copyright ownership. The ASF licenses this file
8
 * to you under the Apache License, Version 2.0 (the
9
 * "License"); you may not use this file except in compliance
10
 * with the License. You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing,
15
 * software distributed under the License is distributed on an
16
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
 * KIND, either express or implied. See the License for the
18
 * specific language governing permissions and limitations
19
 * under the License.
20
 */
21
 
22
$GLOBALS['THRIFT_ROOT'] = '../../lib/php/src';
23
 
24
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
25
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
26
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
27
require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';
28
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
29
 
30
/**
31
 * Suppress errors in here, which happen because we have not installed into
32
 * $GLOBALS['THRIFT_ROOT'].'/packages/tutorial' like we are supposed to!
33
 *
34
 * Normally we would only have to include Calculator.php which would properly
35
 * include the other files from their packages/ folder locations, but we
36
 * include everything here due to the bogus path setup.
37
 */
38
error_reporting(E_NONE);
39
$GEN_DIR = '../gen-php';
40
require_once $GEN_DIR.'/SharedService.php';
41
require_once $GEN_DIR.'/shared_types.php';
42
require_once $GEN_DIR.'/Calculator.php';
43
require_once $GEN_DIR.'/tutorial_types.php';
44
error_reporting(E_ALL);
45
 
46
try {
47
  if (array_search('--http', $argv)) {
48
    $socket = new THttpClient('localhost', 8080, '/php/PhpServer.php');
49
  } else {
50
    $socket = new TSocket('localhost', 9090);
51
  }
52
  $transport = new TBufferedTransport($socket, 1024, 1024);
53
  $protocol = new TBinaryProtocol($transport);
54
  $client = new CalculatorClient($protocol);
55
 
56
  $transport->open();
57
 
58
  $client->ping();
59
  print "ping()\n";
60
 
61
  $sum = $client->add(1,1);
62
  print "1+1=$sum\n";
63
 
64
  $work = new tutorial_Work();
65
 
66
  $work->op = tutorial_Operation::DIVIDE;
67
  $work->num1 = 1;
68
  $work->num2 = 0;
69
 
70
  try {
71
    $client->calculate(1, $work);
72
    print "Whoa! We can divide by zero?\n";
73
  } catch (tutorial_InvalidOperation $io) {
74
    print "InvalidOperation: $io->why\n";
75
  }
76
 
77
  $work->op = tutorial_Operation::SUBTRACT;
78
  $work->num1 = 15;
79
  $work->num2 = 10;
80
  $diff = $client->calculate(1, $work);
81
  print "15-10=$diff\n";
82
 
83
  $log = $client->getStruct(1);
84
  print "Log: $log->value\n";
85
 
86
  $transport->close();
87
 
88
} catch (TException $tx) {
89
  print 'TException: '.$tx->getMessage()."\n";
90
}
91
 
92
?>