From c290c115fadfe1ae0bdbbadd756f3f5962b0fc6d Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 31 Jan 2017 20:29:17 -0800 Subject: PHP: update examples --- examples/php/composer.json | 8 +- examples/php/greeter_client.php | 10 +- examples/php/helloworld.pb.php | 58 ++ examples/php/helloworld.php | 168 ----- examples/php/helloworld.proto | 50 -- examples/php/helloworld_grpc_pb.php | 64 ++ examples/php/route_guide/route_guide.pb.php | 209 ++++++ examples/php/route_guide/route_guide.php | 789 ----------------------- examples/php/route_guide/route_guide.proto | 120 ---- examples/php/route_guide/route_guide_client.php | 22 +- examples/php/route_guide/route_guide_grpc_pb.php | 116 ++++ 11 files changed, 473 insertions(+), 1141 deletions(-) create mode 100644 examples/php/helloworld.pb.php delete mode 100644 examples/php/helloworld.php delete mode 100644 examples/php/helloworld.proto create mode 100644 examples/php/helloworld_grpc_pb.php create mode 100644 examples/php/route_guide/route_guide.pb.php delete mode 100644 examples/php/route_guide/route_guide.php delete mode 100644 examples/php/route_guide/route_guide.proto create mode 100644 examples/php/route_guide/route_guide_grpc_pb.php (limited to 'examples/php') diff --git a/examples/php/composer.json b/examples/php/composer.json index 3d1a95d004..f0b9977252 100644 --- a/examples/php/composer.json +++ b/examples/php/composer.json @@ -2,7 +2,11 @@ "name": "grpc/grpc-demo", "description": "gRPC example for PHP", "require": { - "ext-grpc": "*", - "grpc/grpc": "v1.0.0" + "grpc/grpc": "v1.1.0" + }, + "autoload": { + "psr-4": { + "": "route_guide/" + } } } diff --git a/examples/php/greeter_client.php b/examples/php/greeter_client.php index a5c0865393..986a4bbb85 100644 --- a/examples/php/greeter_client.php +++ b/examples/php/greeter_client.php @@ -33,14 +33,18 @@ */ require dirname(__FILE__).'/vendor/autoload.php'; -require dirname(__FILE__).'/helloworld.php'; + +// The following includes are needed when using protobuf 3.1.0 +// and will suppress warnings when using protobuf 3.2.0+ +@include_once dirname(__FILE__).'/helloworld.pb.php'; +@include_once dirname(__FILE__).'/helloworld_grpc_pb.php'; function greet($name) { - $client = new helloworld\GreeterClient('localhost:50051', [ + $client = new Helloworld\GreeterClient('localhost:50051', [ 'credentials' => Grpc\ChannelCredentials::createInsecure(), ]); - $request = new helloworld\HelloRequest(); + $request = new Helloworld\HelloRequest(); $request->setName($name); list($reply, $status) = $client->SayHello($request)->wait(); $message = $reply->getMessage(); diff --git a/examples/php/helloworld.pb.php b/examples/php/helloworld.pb.php new file mode 100644 index 0000000000..757a4a58f5 --- /dev/null +++ b/examples/php/helloworld.pb.php @@ -0,0 +1,58 @@ +name; + } + + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + } + +} + +class HelloReply extends \Google\Protobuf\Internal\Message +{ + private $message = ''; + + public function getMessage() + { + return $this->message; + } + + public function setMessage($var) + { + GPBUtil::checkString($var, True); + $this->message = $var; + } + +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0ae6010a1068656c6c6f776f726c642e70726f746f120a68656c6c6f776f" . + "726c64221c0a0c48656c6c6f52657175657374120c0a046e616d65180120" . + "012809221d0a0a48656c6c6f5265706c79120f0a076d6573736167651801" . + "2001280932490a0747726565746572123e0a0853617948656c6c6f12182e" . + "68656c6c6f776f726c642e48656c6c6f526571756573741a162e68656c6c" . + "6f776f726c642e48656c6c6f5265706c79220042360a1b696f2e67727063" . + "2e6578616d706c65732e68656c6c6f776f726c64420f48656c6c6f576f72" . + "6c6450726f746f5001a20203484c57620670726f746f33" +)); + diff --git a/examples/php/helloworld.php b/examples/php/helloworld.php deleted file mode 100644 index 697f52aa65..0000000000 --- a/examples/php/helloworld.php +++ /dev/null @@ -1,168 +0,0 @@ -number = 1; - $f->name = 'name'; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasName() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \helloworld\HelloRequest - */ - public function clearName() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return string - */ - public function getName() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param string $value - * - * @return \helloworld\HelloRequest - */ - public function setName($value) - { - return $this->_set(1, $value); - } - } -} - -namespace helloworld { - - class HelloReply extends \DrSlump\Protobuf\Message - { - /** @var string */ - public $message = null; - - /** @var \Closure[] */ - protected static $__extensions = array(); - - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'helloworld.HelloReply'); - - // OPTIONAL STRING message = 1 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = 'message'; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasMessage() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \helloworld\HelloReply - */ - public function clearMessage() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return string - */ - public function getMessage() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param string $value - * - * @return \helloworld\HelloReply - */ - public function setMessage($value) - { - return $this->_set(1, $value); - } - } -} - -namespace helloworld { - - class GreeterClient extends \Grpc\BaseStub - { - public function __construct($hostname, $opts) - { - parent::__construct($hostname, $opts); - } - /** - * @param helloworld\HelloRequest $input - */ - public function SayHello(\helloworld\HelloRequest $argument, $metadata = array(), $options = array()) - { - return $this->_simpleRequest('/helloworld.Greeter/SayHello', $argument, '\helloworld\HelloReply::deserialize', $metadata, $options); - } - } -} diff --git a/examples/php/helloworld.proto b/examples/php/helloworld.proto deleted file mode 100644 index ad8f7a1524..0000000000 --- a/examples/php/helloworld.proto +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto2"; - -option java_package = "ex.grpc"; - -package helloworld; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -// The request message containing the user's name. -message HelloRequest { - optional string name = 1; -} - -// The response message containing the greetings -message HelloReply { - optional string message = 1; -} diff --git a/examples/php/helloworld_grpc_pb.php b/examples/php/helloworld_grpc_pb.php new file mode 100644 index 0000000000..cae48bcfe6 --- /dev/null +++ b/examples/php/helloworld_grpc_pb.php @@ -0,0 +1,64 @@ +_simpleRequest('/helloworld.Greeter/SayHello', + $argument, + ['\Helloworld\HelloReply', 'decode'], + $metadata, $options); + } + + } + +} diff --git a/examples/php/route_guide/route_guide.pb.php b/examples/php/route_guide/route_guide.pb.php new file mode 100644 index 0000000000..78f3ea6e2a --- /dev/null +++ b/examples/php/route_guide/route_guide.pb.php @@ -0,0 +1,209 @@ +latitude; + } + + public function setLatitude($var) + { + GPBUtil::checkInt32($var); + $this->latitude = $var; + } + + public function getLongitude() + { + return $this->longitude; + } + + public function setLongitude($var) + { + GPBUtil::checkInt32($var); + $this->longitude = $var; + } + +} + +class Rectangle extends \Google\Protobuf\Internal\Message +{ + private $lo = null; + private $hi = null; + + public function getLo() + { + return $this->lo; + } + + public function setLo(&$var) + { + GPBUtil::checkMessage($var, \Routeguide\Point::class); + $this->lo = $var; + } + + public function getHi() + { + return $this->hi; + } + + public function setHi(&$var) + { + GPBUtil::checkMessage($var, \Routeguide\Point::class); + $this->hi = $var; + } + +} + +class Feature extends \Google\Protobuf\Internal\Message +{ + private $name = ''; + private $location = null; + + public function getName() + { + return $this->name; + } + + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + } + + public function getLocation() + { + return $this->location; + } + + public function setLocation(&$var) + { + GPBUtil::checkMessage($var, \Routeguide\Point::class); + $this->location = $var; + } + +} + +class RouteNote extends \Google\Protobuf\Internal\Message +{ + private $location = null; + private $message = ''; + + public function getLocation() + { + return $this->location; + } + + public function setLocation(&$var) + { + GPBUtil::checkMessage($var, \Routeguide\Point::class); + $this->location = $var; + } + + public function getMessage() + { + return $this->message; + } + + public function setMessage($var) + { + GPBUtil::checkString($var, True); + $this->message = $var; + } + +} + +class RouteSummary extends \Google\Protobuf\Internal\Message +{ + private $point_count = 0; + private $feature_count = 0; + private $distance = 0; + private $elapsed_time = 0; + + public function getPointCount() + { + return $this->point_count; + } + + public function setPointCount($var) + { + GPBUtil::checkInt32($var); + $this->point_count = $var; + } + + public function getFeatureCount() + { + return $this->feature_count; + } + + public function setFeatureCount($var) + { + GPBUtil::checkInt32($var); + $this->feature_count = $var; + } + + public function getDistance() + { + return $this->distance; + } + + public function setDistance($var) + { + GPBUtil::checkInt32($var); + $this->distance = $var; + } + + public function getElapsedTime() + { + return $this->elapsed_time; + } + + public function setElapsedTime($var) + { + GPBUtil::checkInt32($var); + $this->elapsed_time = $var; + } + +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0ac5050a11726f7574655f67756964652e70726f746f120a726f75746567" . + "75696465222c0a05506f696e7412100a086c617469747564651801200128" . + "0512110a096c6f6e67697475646518022001280522490a0952656374616e" . + "676c65121d0a026c6f18012001280b32112e726f75746567756964652e50" . + "6f696e74121d0a02686918022001280b32112e726f75746567756964652e" . + "506f696e74223c0a0746656174757265120c0a046e616d65180120012809" . + "12230a086c6f636174696f6e18022001280b32112e726f75746567756964" . + "652e506f696e7422410a09526f7574654e6f746512230a086c6f63617469" . + "6f6e18012001280b32112e726f75746567756964652e506f696e74120f0a" . + "076d65737361676518022001280922620a0c526f75746553756d6d617279" . + "12130a0b706f696e745f636f756e7418012001280512150a0d6665617475" . + "72655f636f756e7418022001280512100a0864697374616e636518032001" . + "280512140a0c656c61707365645f74696d651804200128053285020a0a52" . + "6f757465477569646512360a0a4765744665617475726512112e726f7574" . + "6567756964652e506f696e741a132e726f75746567756964652e46656174" . + "7572652200123e0a0c4c697374466561747572657312152e726f75746567" . + "756964652e52656374616e676c651a132e726f75746567756964652e4665" . + "617475726522003001123e0a0b5265636f7264526f75746512112e726f75" . + "746567756964652e506f696e741a182e726f75746567756964652e526f75" . + "746553756d6d61727922002801123f0a09526f7574654368617412152e72" . + "6f75746567756964652e526f7574654e6f74651a152e726f757465677569" . + "64652e526f7574654e6f746522002801300142360a1b696f2e677270632e" . + "6578616d706c65732e726f7574656775696465420f526f75746547756964" . + "6550726f746f5001a20203525447620670726f746f33" +)); + diff --git a/examples/php/route_guide/route_guide.php b/examples/php/route_guide/route_guide.php deleted file mode 100644 index 65045d01e1..0000000000 --- a/examples/php/route_guide/route_guide.php +++ /dev/null @@ -1,789 +0,0 @@ -number = 1; - $f->name = 'latitude'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - // OPTIONAL INT32 longitude = 2 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = 'longitude'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasLatitude() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \routeguide\Point - */ - public function clearLatitude() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return int - */ - public function getLatitude() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\Point - */ - public function setLatitude($value) - { - return $this->_set(1, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasLongitude() - { - return $this->_has(2); - } - - /** - * Clear value. - * - * @return \routeguide\Point - */ - public function clearLongitude() - { - return $this->_clear(2); - } - - /** - * Get value. - * - * @return int - */ - public function getLongitude() - { - return $this->_get(2); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\Point - */ - public function setLongitude($value) - { - return $this->_set(2, $value); - } - } -} - -namespace routeguide { - - class Rectangle extends \DrSlump\Protobuf\Message - { - /** @var \routeguide\Point */ - public $lo = null; - - /** @var \routeguide\Point */ - public $hi = null; - - /** @var \Closure[] */ - protected static $__extensions = array(); - - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Rectangle'); - - // OPTIONAL MESSAGE lo = 1 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = 'lo'; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - // OPTIONAL MESSAGE hi = 2 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = 'hi'; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasLo() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \routeguide\Rectangle - */ - public function clearLo() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return \routeguide\Point - */ - public function getLo() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param \routeguide\Point $value - * - * @return \routeguide\Rectangle - */ - public function setLo(\routeguide\Point $value) - { - return $this->_set(1, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasHi() - { - return $this->_has(2); - } - - /** - * Clear value. - * - * @return \routeguide\Rectangle - */ - public function clearHi() - { - return $this->_clear(2); - } - - /** - * Get value. - * - * @return \routeguide\Point - */ - public function getHi() - { - return $this->_get(2); - } - - /** - * Set value. - * - * @param \routeguide\Point $value - * - * @return \routeguide\Rectangle - */ - public function setHi(\routeguide\Point $value) - { - return $this->_set(2, $value); - } - } -} - -namespace routeguide { - - class Feature extends \DrSlump\Protobuf\Message - { - /** @var string */ - public $name = null; - - /** @var \routeguide\Point */ - public $location = null; - - /** @var \Closure[] */ - protected static $__extensions = array(); - - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Feature'); - - // OPTIONAL STRING name = 1 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = 'name'; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - // OPTIONAL MESSAGE location = 2 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = 'location'; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasName() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \routeguide\Feature - */ - public function clearName() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return string - */ - public function getName() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param string $value - * - * @return \routeguide\Feature - */ - public function setName($value) - { - return $this->_set(1, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasLocation() - { - return $this->_has(2); - } - - /** - * Clear value. - * - * @return \routeguide\Feature - */ - public function clearLocation() - { - return $this->_clear(2); - } - - /** - * Get value. - * - * @return \routeguide\Point - */ - public function getLocation() - { - return $this->_get(2); - } - - /** - * Set value. - * - * @param \routeguide\Point $value - * - * @return \routeguide\Feature - */ - public function setLocation(\routeguide\Point $value) - { - return $this->_set(2, $value); - } - } -} - -namespace routeguide { - - class RouteNote extends \DrSlump\Protobuf\Message - { - /** @var \routeguide\Point */ - public $location = null; - - /** @var string */ - public $message = null; - - /** @var \Closure[] */ - protected static $__extensions = array(); - - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteNote'); - - // OPTIONAL MESSAGE location = 1 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = 'location'; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - // OPTIONAL STRING message = 2 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = 'message'; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasLocation() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \routeguide\RouteNote - */ - public function clearLocation() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return \routeguide\Point - */ - public function getLocation() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param \routeguide\Point $value - * - * @return \routeguide\RouteNote - */ - public function setLocation(\routeguide\Point $value) - { - return $this->_set(1, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasMessage() - { - return $this->_has(2); - } - - /** - * Clear value. - * - * @return \routeguide\RouteNote - */ - public function clearMessage() - { - return $this->_clear(2); - } - - /** - * Get value. - * - * @return string - */ - public function getMessage() - { - return $this->_get(2); - } - - /** - * Set value. - * - * @param string $value - * - * @return \routeguide\RouteNote - */ - public function setMessage($value) - { - return $this->_set(2, $value); - } - } -} - -namespace routeguide { - - class RouteSummary extends \DrSlump\Protobuf\Message - { - /** @var int */ - public $point_count = 0; - - /** @var int */ - public $feature_count = 0; - - /** @var int */ - public $distance = 0; - - /** @var int */ - public $elapsed_time = 0; - - /** @var \Closure[] */ - protected static $__extensions = array(); - - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteSummary'); - - // OPTIONAL INT32 point_count = 1 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = 'point_count'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - // OPTIONAL INT32 feature_count = 2 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = 'feature_count'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - // OPTIONAL INT32 distance = 3 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 3; - $f->name = 'distance'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - // OPTIONAL INT32 elapsed_time = 4 - $f = new \DrSlump\Protobuf\Field(); - $f->number = 4; - $f->name = 'elapsed_time'; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } - - return $descriptor; - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasPointCount() - { - return $this->_has(1); - } - - /** - * Clear value. - * - * @return \routeguide\RouteSummary - */ - public function clearPointCount() - { - return $this->_clear(1); - } - - /** - * Get value. - * - * @return int - */ - public function getPointCount() - { - return $this->_get(1); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\RouteSummary - */ - public function setPointCount($value) - { - return $this->_set(1, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasFeatureCount() - { - return $this->_has(2); - } - - /** - * Clear value. - * - * @return \routeguide\RouteSummary - */ - public function clearFeatureCount() - { - return $this->_clear(2); - } - - /** - * Get value. - * - * @return int - */ - public function getFeatureCount() - { - return $this->_get(2); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\RouteSummary - */ - public function setFeatureCount($value) - { - return $this->_set(2, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasDistance() - { - return $this->_has(3); - } - - /** - * Clear value. - * - * @return \routeguide\RouteSummary - */ - public function clearDistance() - { - return $this->_clear(3); - } - - /** - * Get value. - * - * @return int - */ - public function getDistance() - { - return $this->_get(3); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\RouteSummary - */ - public function setDistance($value) - { - return $this->_set(3, $value); - } - - /** - * Check if has a value. - * - * @return bool - */ - public function hasElapsedTime() - { - return $this->_has(4); - } - - /** - * Clear value. - * - * @return \routeguide\RouteSummary - */ - public function clearElapsedTime() - { - return $this->_clear(4); - } - - /** - * Get value. - * - * @return int - */ - public function getElapsedTime() - { - return $this->_get(4); - } - - /** - * Set value. - * - * @param int $value - * - * @return \routeguide\RouteSummary - */ - public function setElapsedTime($value) - { - return $this->_set(4, $value); - } - } -} - -namespace routeguide { - - class RouteGuideClient extends \Grpc\BaseStub - { - public function __construct($hostname, $opts) - { - parent::__construct($hostname, $opts); - } - /** - * @param routeguide\Point $input - */ - public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) - { - return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options); - } - /** - * @param routeguide\Rectangle $input - */ - public function ListFeatures($argument, $metadata = array(), $options = array()) - { - return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options); - } - /** - * @param routeguide\Point $input - */ - public function RecordRoute($metadata = array()) - { - return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata); - } - /** - * @param routeguide\RouteNote $input - */ - public function RouteChat($metadata = array()) - { - return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); - } - } -} diff --git a/examples/php/route_guide/route_guide.proto b/examples/php/route_guide/route_guide.proto deleted file mode 100644 index d50f8a5169..0000000000 --- a/examples/php/route_guide/route_guide.proto +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto2"; - -option java_package = "io.grpc.examples"; - -package routeguide; - -// Interface exported by the server. -service RouteGuide { - // A simple RPC. - // - // Obtains the feature at a given position. - rpc GetFeature(Point) returns (Feature) {} - - // A server-to-client streaming RPC. - // - // Obtains the Features available within the given Rectangle. Results are - // streamed rather than returned at once (e.g. in a response message with a - // repeated field), as the rectangle may cover a large area and contain a - // huge number of features. - rpc ListFeatures(Rectangle) returns (stream Feature) {} - - // A client-to-server streaming RPC. - // - // Accepts a stream of Points on a route being traversed, returning a - // RouteSummary when traversal is completed. - rpc RecordRoute(stream Point) returns (RouteSummary) {} - - // A Bidirectional streaming RPC. - // - // Accepts a stream of RouteNotes sent while a route is being traversed, - // while receiving other RouteNotes (e.g. from other users). - rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -} - -// Points are represented as latitude-longitude pairs in the E7 representation -// (degrees multiplied by 10**7 and rounded to the nearest integer). -// Latitudes should be in the range +/- 90 degrees and longitude should be in -// the range +/- 180 degrees (inclusive). -message Point { - optional int32 latitude = 1 [default = 0]; - optional int32 longitude = 2 [default = 0]; -} - -// A latitude-longitude rectangle, represented as two diagonally opposite -// points "lo" and "hi". -message Rectangle { - // One corner of the rectangle. - optional Point lo = 1; - - // The other corner of the rectangle. - optional Point hi = 2; -} - -// A feature names something at a given point. -// -// If a feature could not be named, the name is empty. -message Feature { - // The name of the feature. - optional string name = 1; - - // The point where the feature is detected. - optional Point location = 2; -} - -// A RouteNote is a message sent while at a given point. -message RouteNote { - // The location from which the message is sent. - optional Point location = 1; - - // The message to be sent. - optional string message = 2; -} - -// A RouteSummary is received in response to a RecordRoute rpc. -// -// It contains the number of individual points received, the number of -// detected features, and the total distance covered as the cumulative sum of -// the distance between each point. -message RouteSummary { - // The number of points received. - optional int32 point_count = 1 [default = 0]; - - // The number of known features passed while traversing the route. - optional int32 feature_count = 2 [default = 0]; - - // The distance covered in metres. - optional int32 distance = 3 [default = 0]; - - // The duration of the traversal in seconds. - optional int32 elapsed_time = 4 [default = 0]; -} diff --git a/examples/php/route_guide/route_guide_client.php b/examples/php/route_guide/route_guide_client.php index b3cd606797..3f38c262a0 100644 --- a/examples/php/route_guide/route_guide_client.php +++ b/examples/php/route_guide/route_guide_client.php @@ -33,11 +33,15 @@ */ require dirname(__FILE__).'/../vendor/autoload.php'; -require dirname(__FILE__).'/route_guide.php'; + +// The following includes are needed when using protobuf 3.1.0 +// and will suppress warnings when using protobuf 3.2.0+ +@include_once dirname(__FILE__).'/route_guide.pb.php'; +@include_once dirname(__FILE__).'/route_guide_grpc_pb.php'; define('COORD_FACTOR', 1e7); -$client = new routeguide\RouteGuideClient('localhost:50051', [ +$client = new Routeguide\RouteGuideClient('localhost:50051', [ 'credentials' => Grpc\ChannelCredentials::createInsecure(), ]); @@ -63,7 +67,7 @@ function runGetFeature() echo "Running GetFeature...\n"; global $client; - $point = new routeguide\Point(); + $point = new Routeguide\Point(); $points = array( array(409146138, -746188906), array(0, 0), @@ -88,15 +92,15 @@ function runListFeatures() echo "Running ListFeatures...\n"; global $client; - $lo_point = new routeguide\Point(); - $hi_point = new routeguide\Point(); + $lo_point = new Routeguide\Point(); + $hi_point = new Routeguide\Point(); $lo_point->setLatitude(400000000); $lo_point->setLongitude(-750000000); $hi_point->setLatitude(420000000); $hi_point->setLongitude(-730000000); - $rectangle = new routeguide\Rectangle(); + $rectangle = new Routeguide\Rectangle(); $rectangle->setLo($lo_point); $rectangle->setHi($hi_point); @@ -126,7 +130,7 @@ function runRecordRoute() $num_points_in_db = count($db); $num_points = 10; for ($i = 0; $i < $num_points; ++$i) { - $point = new routeguide\Point(); + $point = new Routeguide\Point(); $index = rand(0, $num_points_in_db - 1); $lat = $db[$index]['location']['latitude']; $long = $db[$index]['location']['longitude']; @@ -169,11 +173,11 @@ function runRouteChat() ); foreach ($notes as $n) { - $point = new routeguide\Point(); + $point = new Routeguide\Point(); $point->setLatitude($lat = $n[0]); $point->setLongitude($long = $n[1]); - $route_note = new routeguide\RouteNote(); + $route_note = new Routeguide\RouteNote(); $route_note->setLocation($point); $route_note->setMessage($message = $n[2]); diff --git a/examples/php/route_guide/route_guide_grpc_pb.php b/examples/php/route_guide/route_guide_grpc_pb.php new file mode 100644 index 0000000000..fdc55e61a0 --- /dev/null +++ b/examples/php/route_guide/route_guide_grpc_pb.php @@ -0,0 +1,116 @@ +_simpleRequest('/routeguide.RouteGuide/GetFeature', + $argument, + ['\Routeguide\Feature', 'decode'], + $metadata, $options); + } + + /** + * A server-to-client streaming RPC. + * + * Obtains the Features available within the given Rectangle. Results are + * streamed rather than returned at once (e.g. in a response message with a + * repeated field), as the rectangle may cover a large area and contain a + * huge number of features. + * @param \Routeguide\Rectangle $argument input argument + * @param array $metadata metadata + * @param array $options call options + */ + public function ListFeatures(\Routeguide\Rectangle $argument, + $metadata = [], $options = []) { + return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', + $argument, + ['\Routeguide\Feature', 'decode'], + $metadata, $options); + } + + /** + * A client-to-server streaming RPC. + * + * Accepts a stream of Points on a route being traversed, returning a + * RouteSummary when traversal is completed. + * @param array $metadata metadata + * @param array $options call options + */ + public function RecordRoute($metadata = [], $options = []) { + return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', + ['\Routeguide\RouteSummary','decode'], + $metadata, $options); + } + + /** + * A Bidirectional streaming RPC. + * + * Accepts a stream of RouteNotes sent while a route is being traversed, + * while receiving other RouteNotes (e.g. from other users). + * @param array $metadata metadata + * @param array $options call options + */ + public function RouteChat($metadata = [], $options = []) { + return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', + ['\Routeguide\RouteNote','decode'], + $metadata, $options); + } + + } + +} -- cgit v1.2.3