summaryrefslogtreecommitdiff
path: root/tests/plugins/grpc/php_server
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/grpc/php_server')
-rw-r--r--tests/plugins/grpc/php_server/.rr.yaml22
-rw-r--r--tests/plugins/grpc/php_server/composer.json23
-rw-r--r--tests/plugins/grpc/php_server/server.crt15
-rw-r--r--tests/plugins/grpc/php_server/server.key9
-rw-r--r--tests/plugins/grpc/php_server/service.proto11
-rw-r--r--tests/plugins/grpc/php_server/src/EchoService.php17
-rw-r--r--tests/plugins/grpc/php_server/src/GPBMetadata/Service.php27
-rw-r--r--tests/plugins/grpc/php_server/src/Service/EchoInterface.php22
-rw-r--r--tests/plugins/grpc/php_server/src/Service/Message.php58
-rw-r--r--tests/plugins/grpc/php_server/worker-grpc.php26
10 files changed, 230 insertions, 0 deletions
diff --git a/tests/plugins/grpc/php_server/.rr.yaml b/tests/plugins/grpc/php_server/.rr.yaml
new file mode 100644
index 00000000..cc4a9300
--- /dev/null
+++ b/tests/plugins/grpc/php_server/.rr.yaml
@@ -0,0 +1,22 @@
+grpc:
+ listen: "tcp://:9001"
+ proto: "service.proto"
+ tls:
+ key: "server.key"
+ cert: "server.crt"
+ workers:
+ command: "php worker.php"
+ pool:
+ numWorkers: 4
+
+metrics:
+ address: localhost:2112
+
+limit:
+ interval: 1
+ services:
+ grpc:
+ maxMemory: 100
+ TTL: 0
+ idleTTL: 0
+ execTTL: 60 \ No newline at end of file
diff --git a/tests/plugins/grpc/php_server/composer.json b/tests/plugins/grpc/php_server/composer.json
new file mode 100644
index 00000000..b6303291
--- /dev/null
+++ b/tests/plugins/grpc/php_server/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "app/example-grpc-server",
+ "description": "Example GRPC Server",
+ "repositories": [
+ {
+ "type": "path",
+ "url": "../.."
+ }
+ ],
+ "require": {
+ "spiral/php-grpc": "*"
+ },
+ "require-dev": {
+ "grpc/grpc": "^1.36"
+ },
+ "autoload": {
+ "psr-4": {
+ "": "src"
+ }
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
+}
diff --git a/tests/plugins/grpc/php_server/server.crt b/tests/plugins/grpc/php_server/server.crt
new file mode 100644
index 00000000..24d67fd7
--- /dev/null
+++ b/tests/plugins/grpc/php_server/server.crt
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICTTCCAdOgAwIBAgIJAOKyUd+llTRKMAoGCCqGSM49BAMCMGMxCzAJBgNVBAYT
+AlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2Nv
+MRMwEQYDVQQKDApSb2FkUnVubmVyMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTgw
+OTMwMTMzNDUzWhcNMjgwOTI3MTMzNDUzWjBjMQswCQYDVQQGEwJVUzETMBEGA1UE
+CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzETMBEGA1UECgwK
+Um9hZFJ1bm5lcjESMBAGA1UEAwwJbG9jYWxob3N0MHYwEAYHKoZIzj0CAQYFK4EE
+ACIDYgAEVnbShsM+l5RR3wfWWmGhzuFGwNzKCk7i9xyobDIyBUxG/UUSfj7KKlUX
+puDnDEtF5xXcepl744CyIAYFLOXHb5WqI4jCOzG0o9f/00QQ4bQudJOdbqV910QF
+C2vb7Fxro1MwUTAdBgNVHQ4EFgQU9xUexnbB6ORKayA7Pfjzs33otsAwHwYDVR0j
+BBgwFoAU9xUexnbB6ORKayA7Pfjzs33otsAwDwYDVR0TAQH/BAUwAwEB/zAKBggq
+hkjOPQQDAgNoADBlAjEAue3HhR/MUhxoa9tSDBtOJT3FYbDQswrsdqBTz97CGKst
+e7XeZ3HMEvEXy0hGGEMhAjAqcD/4k9vViVppgWFtkk6+NFbm+Kw/QeeAiH5FgFSj
+8xQcb+b7nPwNLp3JOkXkVd4=
+-----END CERTIFICATE-----
diff --git a/tests/plugins/grpc/php_server/server.key b/tests/plugins/grpc/php_server/server.key
new file mode 100644
index 00000000..7501dd46
--- /dev/null
+++ b/tests/plugins/grpc/php_server/server.key
@@ -0,0 +1,9 @@
+-----BEGIN EC PARAMETERS-----
+BgUrgQQAIg==
+-----END EC PARAMETERS-----
+-----BEGIN EC PRIVATE KEY-----
+MIGkAgEBBDCQP8utxNbHR6xZOLAJgUhn88r6IrPqmN0MsgGJM/jePB+T9UhkmIU8
+PMm2HeScbcugBwYFK4EEACKhZANiAARWdtKGwz6XlFHfB9ZaYaHO4UbA3MoKTuL3
+HKhsMjIFTEb9RRJ+PsoqVRem4OcMS0XnFdx6mXvjgLIgBgUs5cdvlaojiMI7MbSj
+1//TRBDhtC50k51upX3XRAULa9vsXGs=
+-----END EC PRIVATE KEY-----
diff --git a/tests/plugins/grpc/php_server/service.proto b/tests/plugins/grpc/php_server/service.proto
new file mode 100644
index 00000000..60ff84a9
--- /dev/null
+++ b/tests/plugins/grpc/php_server/service.proto
@@ -0,0 +1,11 @@
+syntax = "proto3";
+package service;
+
+service Echo {
+ rpc Ping (Message) returns (Message) {
+ }
+}
+
+message Message {
+ string msg = 1;
+} \ No newline at end of file
diff --git a/tests/plugins/grpc/php_server/src/EchoService.php b/tests/plugins/grpc/php_server/src/EchoService.php
new file mode 100644
index 00000000..c2707811
--- /dev/null
+++ b/tests/plugins/grpc/php_server/src/EchoService.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Sample GRPC PHP server.
+ */
+
+use Spiral\GRPC\ContextInterface;
+use Service\EchoInterface;
+use Service\Message;
+
+class EchoService implements EchoInterface
+{
+ public function Ping(ContextInterface $ctx, Message $in): Message
+ {
+ $out = new Message();
+ return $out->setMsg(strtoupper($in->getMsg()));
+ }
+} \ No newline at end of file
diff --git a/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php b/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php
new file mode 100644
index 00000000..c1b65b21
--- /dev/null
+++ b/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php
@@ -0,0 +1,27 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: service.proto
+
+namespace GPBMetadata;
+
+class Service
+{
+ public static $is_initialized = false;
+
+ public static function initOnce() {
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
+
+ if (static::$is_initialized == true) {
+ return;
+ }
+ $pool->internalAddGeneratedFile(hex2bin(
+ "0a6e0a0d736572766963652e70726f746f12077365727669636522160a07" .
+ "4d657373616765120b0a036d736718012001280932340a044563686f122c" .
+ "0a0450696e6712102e736572766963652e4d6573736167651a102e736572" .
+ "766963652e4d6573736167652200620670726f746f33"
+ ));
+
+ static::$is_initialized = true;
+ }
+}
+
diff --git a/tests/plugins/grpc/php_server/src/Service/EchoInterface.php b/tests/plugins/grpc/php_server/src/Service/EchoInterface.php
new file mode 100644
index 00000000..5f336ace
--- /dev/null
+++ b/tests/plugins/grpc/php_server/src/Service/EchoInterface.php
@@ -0,0 +1,22 @@
+<?php
+# Generated by the protocol buffer compiler (spiral/grpc). DO NOT EDIT!
+# source: service.proto
+
+namespace Service;
+
+use Spiral\GRPC;
+
+interface EchoInterface extends GRPC\ServiceInterface
+{
+ // GRPC specific service name.
+ public const NAME = "service.Echo";
+
+ /**
+ * @param GRPC\ContextInterface $ctx
+ * @param Message $in
+ * @return Message
+ *
+ * @throws GRPC\Exception\InvokeException
+ */
+ public function Ping(GRPC\ContextInterface $ctx, Message $in): Message;
+}
diff --git a/tests/plugins/grpc/php_server/src/Service/Message.php b/tests/plugins/grpc/php_server/src/Service/Message.php
new file mode 100644
index 00000000..6c40c879
--- /dev/null
+++ b/tests/plugins/grpc/php_server/src/Service/Message.php
@@ -0,0 +1,58 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: service.proto
+
+namespace Service;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Generated from protobuf message <code>service.Message</code>
+ */
+class Message extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * Generated from protobuf field <code>string msg = 1;</code>
+ */
+ private $msg = '';
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type string $msg
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Service::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * Generated from protobuf field <code>string msg = 1;</code>
+ * @return string
+ */
+ public function getMsg()
+ {
+ return $this->msg;
+ }
+
+ /**
+ * Generated from protobuf field <code>string msg = 1;</code>
+ * @param string $var
+ * @return $this
+ */
+ public function setMsg($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->msg = $var;
+
+ return $this;
+ }
+
+}
+
diff --git a/tests/plugins/grpc/php_server/worker-grpc.php b/tests/plugins/grpc/php_server/worker-grpc.php
new file mode 100644
index 00000000..683a2341
--- /dev/null
+++ b/tests/plugins/grpc/php_server/worker-grpc.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Sample GRPC PHP server.
+ */
+
+use Service\EchoInterface;
+use Spiral\Goridge\StreamRelay;
+use Spiral\GRPC\Server;
+use Spiral\RoadRunner\Worker;
+
+require __DIR__ . '/vendor/autoload.php';
+
+$server = new Server(null, [
+ 'debug' => false, // optional (default: false)
+]);
+
+$server->registerService(EchoInterface::class, new EchoService());
+
+$worker = \method_exists(Worker::class, 'create')
+ // RoadRunner >= 2.x
+ ? Worker::create()
+ // RoadRunner 1.x
+ : new Worker(new StreamRelay(STDIN, STDOUT))
+;
+
+$server->serve($worker);