php: fix examples/ directory as well

pull/6659/head
Stanley Cheung 9 years ago
parent d55ddbcbe3
commit 46d94bb4aa
  1. 12
      examples/php/greeter_client.php
  2. 70
      examples/php/helloworld.php
  3. 344
      examples/php/route_guide/route_guide.php
  4. 50
      examples/php/route_guide/route_guide_client.php

@ -32,19 +32,21 @@
* *
*/ */
require dirname(__FILE__) . '/vendor/autoload.php'; require dirname(__FILE__).'/vendor/autoload.php';
require dirname(__FILE__) . '/helloworld.php'; require dirname(__FILE__).'/helloworld.php';
function greet($name) { function greet($name)
{
$client = new helloworld\GreeterClient('localhost:50051', [ $client = new helloworld\GreeterClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure() 'credentials' => Grpc\ChannelCredentials::createInsecure(),
]); ]);
$request = new helloworld\HelloRequest(); $request = new helloworld\HelloRequest();
$request->setName($name); $request->setName($name);
list($reply, $status) = $client->SayHello($request)->wait(); list($reply, $status) = $client->SayHello($request)->wait();
$message = $reply->getMessage(); $message = $reply->getMessage();
return $message; return $message;
} }
$name = !empty($argv[1]) ? $argv[1] : 'world'; $name = !empty($argv[1]) ? $argv[1] : 'world';
print(greet($name)."\n"); echo greet($name)."\n";

@ -5,12 +5,11 @@
namespace helloworld { namespace helloworld {
class HelloRequest extends \DrSlump\Protobuf\Message { class HelloRequest extends \DrSlump\Protobuf\Message
{
/** @var string */ /** @var string */
public $name = null; public $name = null;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -21,7 +20,7 @@ namespace helloworld {
// OPTIONAL STRING name = 1 // OPTIONAL STRING name = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "name"; $f->name = 'name';
$f->type = \DrSlump\Protobuf::TYPE_STRING; $f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f); $descriptor->addField($f);
@ -34,39 +33,44 @@ namespace helloworld {
} }
/** /**
* Check if <name> has a value * Check if <name> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasName(){ public function hasName()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <name> value * Clear <name> value.
* *
* @return \helloworld\HelloRequest * @return \helloworld\HelloRequest
*/ */
public function clearName(){ public function clearName()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <name> value * Get <name> value.
* *
* @return string * @return string
*/ */
public function getName(){ public function getName()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <name> value * Set <name> value.
* *
* @param string $value * @param string $value
*
* @return \helloworld\HelloRequest * @return \helloworld\HelloRequest
*/ */
public function setName( $value){ public function setName($value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
} }
@ -74,12 +78,11 @@ namespace helloworld {
namespace helloworld { namespace helloworld {
class HelloReply extends \DrSlump\Protobuf\Message { class HelloReply extends \DrSlump\Protobuf\Message
{
/** @var string */ /** @var string */
public $message = null; public $message = null;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -90,7 +93,7 @@ namespace helloworld {
// OPTIONAL STRING message = 1 // OPTIONAL STRING message = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "message"; $f->name = 'message';
$f->type = \DrSlump\Protobuf::TYPE_STRING; $f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f); $descriptor->addField($f);
@ -103,39 +106,44 @@ namespace helloworld {
} }
/** /**
* Check if <message> has a value * Check if <message> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasMessage(){ public function hasMessage()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <message> value * Clear <message> value.
* *
* @return \helloworld\HelloReply * @return \helloworld\HelloReply
*/ */
public function clearMessage(){ public function clearMessage()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <message> value * Get <message> value.
* *
* @return string * @return string
*/ */
public function getMessage(){ public function getMessage()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <message> value * Set <message> value.
* *
* @param string $value * @param string $value
*
* @return \helloworld\HelloReply * @return \helloworld\HelloReply
*/ */
public function setMessage( $value){ public function setMessage($value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
} }
@ -143,15 +151,17 @@ namespace helloworld {
namespace helloworld { namespace helloworld {
class GreeterClient extends \Grpc\BaseStub { class GreeterClient extends \Grpc\BaseStub
{
public function __construct($hostname, $opts) { public function __construct($hostname, $opts)
{
parent::__construct($hostname, $opts); parent::__construct($hostname, $opts);
} }
/** /**
* @param helloworld\HelloRequest $input * @param helloworld\HelloRequest $input
*/ */
public function SayHello(\helloworld\HelloRequest $argument, $metadata = array(), $options = array()) { public function SayHello(\helloworld\HelloRequest $argument, $metadata = array(), $options = array())
{
return $this->_simpleRequest('/helloworld.Greeter/SayHello', $argument, '\helloworld\HelloReply::deserialize', $metadata, $options); return $this->_simpleRequest('/helloworld.Greeter/SayHello', $argument, '\helloworld\HelloReply::deserialize', $metadata, $options);
} }
} }

@ -5,15 +5,14 @@
namespace routeguide { namespace routeguide {
class Point extends \DrSlump\Protobuf\Message { class Point extends \DrSlump\Protobuf\Message
{
/** @var int */ /** @var int */
public $latitude = 0; public $latitude = 0;
/** @var int */ /** @var int */
public $longitude = 0; public $longitude = 0;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -24,7 +23,7 @@ namespace routeguide {
// OPTIONAL INT32 latitude = 1 // OPTIONAL INT32 latitude = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "latitude"; $f->name = 'latitude';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -33,7 +32,7 @@ namespace routeguide {
// OPTIONAL INT32 longitude = 2 // OPTIONAL INT32 longitude = 2
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 2; $f->number = 2;
$f->name = "longitude"; $f->name = 'longitude';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -47,76 +46,86 @@ namespace routeguide {
} }
/** /**
* Check if <latitude> has a value * Check if <latitude> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasLatitude(){ public function hasLatitude()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <latitude> value * Clear <latitude> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function clearLatitude(){ public function clearLatitude()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <latitude> value * Get <latitude> value.
* *
* @return int * @return int
*/ */
public function getLatitude(){ public function getLatitude()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <latitude> value * Set <latitude> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function setLatitude( $value){ public function setLatitude($value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
/** /**
* Check if <longitude> has a value * Check if <longitude> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasLongitude(){ public function hasLongitude()
{
return $this->_has(2); return $this->_has(2);
} }
/** /**
* Clear <longitude> value * Clear <longitude> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function clearLongitude(){ public function clearLongitude()
{
return $this->_clear(2); return $this->_clear(2);
} }
/** /**
* Get <longitude> value * Get <longitude> value.
* *
* @return int * @return int
*/ */
public function getLongitude(){ public function getLongitude()
{
return $this->_get(2); return $this->_get(2);
} }
/** /**
* Set <longitude> value * Set <longitude> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function setLongitude( $value){ public function setLongitude($value)
{
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
@ -124,15 +133,14 @@ namespace routeguide {
namespace routeguide { namespace routeguide {
class Rectangle extends \DrSlump\Protobuf\Message { class Rectangle extends \DrSlump\Protobuf\Message
{
/** @var \routeguide\Point */ /** @var \routeguide\Point */
public $lo = null; public $lo = null;
/** @var \routeguide\Point */ /** @var \routeguide\Point */
public $hi = null; public $hi = null;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -143,7 +151,7 @@ namespace routeguide {
// OPTIONAL MESSAGE lo = 1 // OPTIONAL MESSAGE lo = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "lo"; $f->name = 'lo';
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\routeguide\Point'; $f->reference = '\routeguide\Point';
@ -152,7 +160,7 @@ namespace routeguide {
// OPTIONAL MESSAGE hi = 2 // OPTIONAL MESSAGE hi = 2
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 2; $f->number = 2;
$f->name = "hi"; $f->name = 'hi';
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\routeguide\Point'; $f->reference = '\routeguide\Point';
@ -166,76 +174,86 @@ namespace routeguide {
} }
/** /**
* Check if <lo> has a value * Check if <lo> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasLo(){ public function hasLo()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <lo> value * Clear <lo> value.
* *
* @return \routeguide\Rectangle * @return \routeguide\Rectangle
*/ */
public function clearLo(){ public function clearLo()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <lo> value * Get <lo> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function getLo(){ public function getLo()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <lo> value * Set <lo> value.
* *
* @param \routeguide\Point $value * @param \routeguide\Point $value
*
* @return \routeguide\Rectangle * @return \routeguide\Rectangle
*/ */
public function setLo(\routeguide\Point $value){ public function setLo(\routeguide\Point $value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
/** /**
* Check if <hi> has a value * Check if <hi> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasHi(){ public function hasHi()
{
return $this->_has(2); return $this->_has(2);
} }
/** /**
* Clear <hi> value * Clear <hi> value.
* *
* @return \routeguide\Rectangle * @return \routeguide\Rectangle
*/ */
public function clearHi(){ public function clearHi()
{
return $this->_clear(2); return $this->_clear(2);
} }
/** /**
* Get <hi> value * Get <hi> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function getHi(){ public function getHi()
{
return $this->_get(2); return $this->_get(2);
} }
/** /**
* Set <hi> value * Set <hi> value.
* *
* @param \routeguide\Point $value * @param \routeguide\Point $value
*
* @return \routeguide\Rectangle * @return \routeguide\Rectangle
*/ */
public function setHi(\routeguide\Point $value){ public function setHi(\routeguide\Point $value)
{
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
@ -243,15 +261,14 @@ namespace routeguide {
namespace routeguide { namespace routeguide {
class Feature extends \DrSlump\Protobuf\Message { class Feature extends \DrSlump\Protobuf\Message
{
/** @var string */ /** @var string */
public $name = null; public $name = null;
/** @var \routeguide\Point */ /** @var \routeguide\Point */
public $location = null; public $location = null;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -262,7 +279,7 @@ namespace routeguide {
// OPTIONAL STRING name = 1 // OPTIONAL STRING name = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "name"; $f->name = 'name';
$f->type = \DrSlump\Protobuf::TYPE_STRING; $f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f); $descriptor->addField($f);
@ -270,7 +287,7 @@ namespace routeguide {
// OPTIONAL MESSAGE location = 2 // OPTIONAL MESSAGE location = 2
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 2; $f->number = 2;
$f->name = "location"; $f->name = 'location';
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\routeguide\Point'; $f->reference = '\routeguide\Point';
@ -284,76 +301,86 @@ namespace routeguide {
} }
/** /**
* Check if <name> has a value * Check if <name> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasName(){ public function hasName()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <name> value * Clear <name> value.
* *
* @return \routeguide\Feature * @return \routeguide\Feature
*/ */
public function clearName(){ public function clearName()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <name> value * Get <name> value.
* *
* @return string * @return string
*/ */
public function getName(){ public function getName()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <name> value * Set <name> value.
* *
* @param string $value * @param string $value
*
* @return \routeguide\Feature * @return \routeguide\Feature
*/ */
public function setName( $value){ public function setName($value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
/** /**
* Check if <location> has a value * Check if <location> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasLocation(){ public function hasLocation()
{
return $this->_has(2); return $this->_has(2);
} }
/** /**
* Clear <location> value * Clear <location> value.
* *
* @return \routeguide\Feature * @return \routeguide\Feature
*/ */
public function clearLocation(){ public function clearLocation()
{
return $this->_clear(2); return $this->_clear(2);
} }
/** /**
* Get <location> value * Get <location> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function getLocation(){ public function getLocation()
{
return $this->_get(2); return $this->_get(2);
} }
/** /**
* Set <location> value * Set <location> value.
* *
* @param \routeguide\Point $value * @param \routeguide\Point $value
*
* @return \routeguide\Feature * @return \routeguide\Feature
*/ */
public function setLocation(\routeguide\Point $value){ public function setLocation(\routeguide\Point $value)
{
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
@ -361,15 +388,14 @@ namespace routeguide {
namespace routeguide { namespace routeguide {
class RouteNote extends \DrSlump\Protobuf\Message { class RouteNote extends \DrSlump\Protobuf\Message
{
/** @var \routeguide\Point */ /** @var \routeguide\Point */
public $location = null; public $location = null;
/** @var string */ /** @var string */
public $message = null; public $message = null;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -380,7 +406,7 @@ namespace routeguide {
// OPTIONAL MESSAGE location = 1 // OPTIONAL MESSAGE location = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "location"; $f->name = 'location';
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\routeguide\Point'; $f->reference = '\routeguide\Point';
@ -389,7 +415,7 @@ namespace routeguide {
// OPTIONAL STRING message = 2 // OPTIONAL STRING message = 2
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 2; $f->number = 2;
$f->name = "message"; $f->name = 'message';
$f->type = \DrSlump\Protobuf::TYPE_STRING; $f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f); $descriptor->addField($f);
@ -402,76 +428,86 @@ namespace routeguide {
} }
/** /**
* Check if <location> has a value * Check if <location> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasLocation(){ public function hasLocation()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <location> value * Clear <location> value.
* *
* @return \routeguide\RouteNote * @return \routeguide\RouteNote
*/ */
public function clearLocation(){ public function clearLocation()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <location> value * Get <location> value.
* *
* @return \routeguide\Point * @return \routeguide\Point
*/ */
public function getLocation(){ public function getLocation()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <location> value * Set <location> value.
* *
* @param \routeguide\Point $value * @param \routeguide\Point $value
*
* @return \routeguide\RouteNote * @return \routeguide\RouteNote
*/ */
public function setLocation(\routeguide\Point $value){ public function setLocation(\routeguide\Point $value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
/** /**
* Check if <message> has a value * Check if <message> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasMessage(){ public function hasMessage()
{
return $this->_has(2); return $this->_has(2);
} }
/** /**
* Clear <message> value * Clear <message> value.
* *
* @return \routeguide\RouteNote * @return \routeguide\RouteNote
*/ */
public function clearMessage(){ public function clearMessage()
{
return $this->_clear(2); return $this->_clear(2);
} }
/** /**
* Get <message> value * Get <message> value.
* *
* @return string * @return string
*/ */
public function getMessage(){ public function getMessage()
{
return $this->_get(2); return $this->_get(2);
} }
/** /**
* Set <message> value * Set <message> value.
* *
* @param string $value * @param string $value
*
* @return \routeguide\RouteNote * @return \routeguide\RouteNote
*/ */
public function setMessage( $value){ public function setMessage($value)
{
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
@ -479,8 +515,8 @@ namespace routeguide {
namespace routeguide { namespace routeguide {
class RouteSummary extends \DrSlump\Protobuf\Message { class RouteSummary extends \DrSlump\Protobuf\Message
{
/** @var int */ /** @var int */
public $point_count = 0; public $point_count = 0;
@ -493,7 +529,6 @@ namespace routeguide {
/** @var int */ /** @var int */
public $elapsed_time = 0; public $elapsed_time = 0;
/** @var \Closure[] */ /** @var \Closure[] */
protected static $__extensions = array(); protected static $__extensions = array();
@ -504,7 +539,7 @@ namespace routeguide {
// OPTIONAL INT32 point_count = 1 // OPTIONAL INT32 point_count = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 1; $f->number = 1;
$f->name = "point_count"; $f->name = 'point_count';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -513,7 +548,7 @@ namespace routeguide {
// OPTIONAL INT32 feature_count = 2 // OPTIONAL INT32 feature_count = 2
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 2; $f->number = 2;
$f->name = "feature_count"; $f->name = 'feature_count';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -522,7 +557,7 @@ namespace routeguide {
// OPTIONAL INT32 distance = 3 // OPTIONAL INT32 distance = 3
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 3; $f->number = 3;
$f->name = "distance"; $f->name = 'distance';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -531,7 +566,7 @@ namespace routeguide {
// OPTIONAL INT32 elapsed_time = 4 // OPTIONAL INT32 elapsed_time = 4
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
$f->number = 4; $f->number = 4;
$f->name = "elapsed_time"; $f->name = 'elapsed_time';
$f->type = \DrSlump\Protobuf::TYPE_INT32; $f->type = \DrSlump\Protobuf::TYPE_INT32;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->default = 0; $f->default = 0;
@ -545,150 +580,170 @@ namespace routeguide {
} }
/** /**
* Check if <point_count> has a value * Check if <point_count> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasPointCount(){ public function hasPointCount()
{
return $this->_has(1); return $this->_has(1);
} }
/** /**
* Clear <point_count> value * Clear <point_count> value.
* *
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearPointCount(){ public function clearPointCount()
{
return $this->_clear(1); return $this->_clear(1);
} }
/** /**
* Get <point_count> value * Get <point_count> value.
* *
* @return int * @return int
*/ */
public function getPointCount(){ public function getPointCount()
{
return $this->_get(1); return $this->_get(1);
} }
/** /**
* Set <point_count> value * Set <point_count> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setPointCount( $value){ public function setPointCount($value)
{
return $this->_set(1, $value); return $this->_set(1, $value);
} }
/** /**
* Check if <feature_count> has a value * Check if <feature_count> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasFeatureCount(){ public function hasFeatureCount()
{
return $this->_has(2); return $this->_has(2);
} }
/** /**
* Clear <feature_count> value * Clear <feature_count> value.
* *
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearFeatureCount(){ public function clearFeatureCount()
{
return $this->_clear(2); return $this->_clear(2);
} }
/** /**
* Get <feature_count> value * Get <feature_count> value.
* *
* @return int * @return int
*/ */
public function getFeatureCount(){ public function getFeatureCount()
{
return $this->_get(2); return $this->_get(2);
} }
/** /**
* Set <feature_count> value * Set <feature_count> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setFeatureCount( $value){ public function setFeatureCount($value)
{
return $this->_set(2, $value); return $this->_set(2, $value);
} }
/** /**
* Check if <distance> has a value * Check if <distance> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasDistance(){ public function hasDistance()
{
return $this->_has(3); return $this->_has(3);
} }
/** /**
* Clear <distance> value * Clear <distance> value.
* *
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearDistance(){ public function clearDistance()
{
return $this->_clear(3); return $this->_clear(3);
} }
/** /**
* Get <distance> value * Get <distance> value.
* *
* @return int * @return int
*/ */
public function getDistance(){ public function getDistance()
{
return $this->_get(3); return $this->_get(3);
} }
/** /**
* Set <distance> value * Set <distance> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setDistance( $value){ public function setDistance($value)
{
return $this->_set(3, $value); return $this->_set(3, $value);
} }
/** /**
* Check if <elapsed_time> has a value * Check if <elapsed_time> has a value.
* *
* @return boolean * @return bool
*/ */
public function hasElapsedTime(){ public function hasElapsedTime()
{
return $this->_has(4); return $this->_has(4);
} }
/** /**
* Clear <elapsed_time> value * Clear <elapsed_time> value.
* *
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearElapsedTime(){ public function clearElapsedTime()
{
return $this->_clear(4); return $this->_clear(4);
} }
/** /**
* Get <elapsed_time> value * Get <elapsed_time> value.
* *
* @return int * @return int
*/ */
public function getElapsedTime(){ public function getElapsedTime()
{
return $this->_get(4); return $this->_get(4);
} }
/** /**
* Set <elapsed_time> value * Set <elapsed_time> value.
* *
* @param int $value * @param int $value
*
* @return \routeguide\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setElapsedTime( $value){ public function setElapsedTime($value)
{
return $this->_set(4, $value); return $this->_set(4, $value);
} }
} }
@ -696,33 +751,38 @@ namespace routeguide {
namespace routeguide { namespace routeguide {
class RouteGuideClient extends \Grpc\BaseStub { class RouteGuideClient extends \Grpc\BaseStub
{
public function __construct($hostname, $opts) { public function __construct($hostname, $opts)
{
parent::__construct($hostname, $opts); parent::__construct($hostname, $opts);
} }
/** /**
* @param routeguide\Point $input * @param routeguide\Point $input
*/ */
public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) { public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array())
{
return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options); return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options);
} }
/** /**
* @param routeguide\Rectangle $input * @param routeguide\Rectangle $input
*/ */
public function ListFeatures($argument, $metadata = array(), $options = array()) { public function ListFeatures($argument, $metadata = array(), $options = array())
{
return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options); return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options);
} }
/** /**
* @param routeguide\Point $input * @param routeguide\Point $input
*/ */
public function RecordRoute($metadata = array()) { public function RecordRoute($metadata = array())
{
return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata); return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata);
} }
/** /**
* @param routeguide\RouteNote $input * @param routeguide\RouteNote $input
*/ */
public function RouteChat($metadata = array()) { public function RouteChat($metadata = array())
{
return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata);
} }
} }

@ -32,23 +32,24 @@
* *
*/ */
require dirname(__FILE__) . '/../vendor/autoload.php'; require dirname(__FILE__).'/../vendor/autoload.php';
require dirname(__FILE__) . '/route_guide.php'; require dirname(__FILE__).'/route_guide.php';
define('COORD_FACTOR', 1e7); define('COORD_FACTOR', 1e7);
$client = new routeguide\RouteGuideClient('localhost:50051', [ $client = new routeguide\RouteGuideClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure() 'credentials' => Grpc\ChannelCredentials::createInsecure(),
]); ]);
function printFeature($feature) { function printFeature($feature)
{
$name = $feature->getName(); $name = $feature->getName();
if (!$name) { if (!$name) {
$name_str = "no feature"; $name_str = 'no feature';
} else { } else {
$name_str = "feature called $name"; $name_str = "feature called $name";
} }
print sprintf("Found %s \n at %f, %f\n", $name_str, echo sprintf("Found %s \n at %f, %f\n", $name_str,
$feature->getLocation()->getLatitude() / COORD_FACTOR, $feature->getLocation()->getLatitude() / COORD_FACTOR,
$feature->getLocation()->getLongitude() / COORD_FACTOR); $feature->getLocation()->getLongitude() / COORD_FACTOR);
} }
@ -57,8 +58,9 @@ function printFeature($feature) {
* Run the getFeature demo. Calls getFeature with a point known to have a * Run the getFeature demo. Calls getFeature with a point known to have a
* feature and a point known not to have a feature. * feature and a point known not to have a feature.
*/ */
function runGetFeature() { function runGetFeature()
print "Running GetFeature...\n"; {
echo "Running GetFeature...\n";
global $client; global $client;
$point = new routeguide\Point(); $point = new routeguide\Point();
@ -81,8 +83,9 @@ function runGetFeature() {
* containing all of the features in the pre-generated * containing all of the features in the pre-generated
* database. Prints each response as it comes in. * database. Prints each response as it comes in.
*/ */
function runListFeatures() { function runListFeatures()
print "Running ListFeatures...\n"; {
echo "Running ListFeatures...\n";
global $client; global $client;
$lo_point = new routeguide\Point(); $lo_point = new routeguide\Point();
@ -111,8 +114,9 @@ function runListFeatures() {
* pre-generated feature database with a variable delay in between. Prints * pre-generated feature database with a variable delay in between. Prints
* the statistics when they are sent from the server. * the statistics when they are sent from the server.
*/ */
function runRecordRoute() { function runRecordRoute()
print "Running RecordRoute...\n"; {
echo "Running RecordRoute...\n";
global $client, $argv; global $client, $argv;
// start the client streaming call // start the client streaming call
@ -121,7 +125,7 @@ function runRecordRoute() {
$db = json_decode(file_get_contents($argv[1]), true); $db = json_decode(file_get_contents($argv[1]), true);
$num_points_in_db = count($db); $num_points_in_db = count($db);
$num_points = 10; $num_points = 10;
for ($i = 0; $i < $num_points; $i++) { for ($i = 0; $i < $num_points; ++$i) {
$point = new routeguide\Point(); $point = new routeguide\Point();
$index = rand(0, $num_points_in_db - 1); $index = rand(0, $num_points_in_db - 1);
$lat = $db[$index]['location']['latitude']; $lat = $db[$index]['location']['latitude'];
@ -129,14 +133,14 @@ function runRecordRoute() {
$feature_name = $db[$index]['name']; $feature_name = $db[$index]['name'];
$point->setLatitude($lat); $point->setLatitude($lat);
$point->setLongitude($long); $point->setLongitude($long);
print sprintf("Visiting point %f, %f,\n with feature name: %s\n", echo sprintf("Visiting point %f, %f,\n with feature name: %s\n",
$lat / COORD_FACTOR, $long / COORD_FACTOR, $lat / COORD_FACTOR, $long / COORD_FACTOR,
$feature_name ? $feature_name : '<empty>'); $feature_name ? $feature_name : '<empty>');
usleep(rand(300000, 800000)); usleep(rand(300000, 800000));
$call->write($point); $call->write($point);
} }
list($route_summary, $status) = $call->wait(); list($route_summary, $status) = $call->wait();
print sprintf("Finished trip with %d points\nPassed %d features\n". echo sprintf("Finished trip with %d points\nPassed %d features\n".
"Travelled %d meters\nIt took %d seconds\n", "Travelled %d meters\nIt took %d seconds\n",
$route_summary->getPointCount(), $route_summary->getPointCount(),
$route_summary->getFeatureCount(), $route_summary->getFeatureCount(),
@ -148,8 +152,9 @@ function runRecordRoute() {
* Run the routeChat demo. Send some chat messages, and print any chat * Run the routeChat demo. Send some chat messages, and print any chat
* messages that are sent from the server. * messages that are sent from the server.
*/ */
function runRouteChat() { function runRouteChat()
print "Running RouteChat...\n"; {
echo "Running RouteChat...\n";
global $client; global $client;
// start the bidirectional streaming call // start the bidirectional streaming call
@ -172,7 +177,7 @@ function runRouteChat() {
$route_note->setLocation($point); $route_note->setLocation($point);
$route_note->setMessage($message = $n[2]); $route_note->setMessage($message = $n[2]);
print sprintf("Sending message: '%s' at (%d, %d)\n", echo sprintf("Sending message: '%s' at (%d, %d)\n",
$message, $lat, $long); $message, $lat, $long);
// send a bunch of messages to the server // send a bunch of messages to the server
$call->write($route_note); $call->write($route_note);
@ -181,7 +186,7 @@ function runRouteChat() {
// read from the server until there's no more // read from the server until there's no more
while ($route_note_reply = $call->read()) { while ($route_note_reply = $call->read()) {
print sprintf("Previous left message at (%d, %d): '%s'\n", echo sprintf("Previous left message at (%d, %d): '%s'\n",
$route_note_reply->getLocation()->getLatitude(), $route_note_reply->getLocation()->getLatitude(),
$route_note_reply->getLocation()->getLongitude(), $route_note_reply->getLocation()->getLongitude(),
$route_note_reply->getMessage()); $route_note_reply->getMessage());
@ -189,9 +194,10 @@ function runRouteChat() {
} }
/** /**
* Run all of the demos in order * Run all of the demos in order.
*/ */
function main() { function main()
{
runGetFeature(); runGetFeature();
runListFeatures(); runListFeatures();
runRecordRoute(); runRecordRoute();
@ -199,7 +205,7 @@ function main() {
} }
if (empty($argv[1])) { if (empty($argv[1])) {
print "Usage: php -d extension=grpc.so route_guide_client.php " . echo 'Usage: php -d extension=grpc.so route_guide_client.php '.
"<path to route_guide_db.json>\n"; "<path to route_guide_db.json>\n";
exit(1); exit(1);
} }

Loading…
Cancel
Save