allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

201
vendor/grpc/grpc/LICENSE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

16
vendor/grpc/grpc/MAINTAINERS.md vendored Normal file
View File

@@ -0,0 +1,16 @@
This page lists all active maintainers of this repository. If you were a
maintainer and would like to add your name to the Emeritus list, please send us a
PR.
See [GOVERNANCE.md](https://github.com/grpc/grpc-community/blob/master/governance.md)
for governance guidelines and how to become a maintainer.
See [CONTRIBUTING.md](https://github.com/grpc/grpc-community/blob/master/CONTRIBUTING.md)
for general contribution guidelines.
## Maintainers (in alphabetical order)
- [stanley-cheung](https://github.com/stanley-cheung), Google Inc.
- [wenbozhu](https://github.com/wenbozhu), Google Inc.
- [zhouyihaiding](https://github.com/zhouyihaiding), Google Inc.
## Emeritus Maintainers (in alphabetical order)
- [murgatroid99](https://github.com/murgatroid99), Google Inc.

9
vendor/grpc/grpc/README.md vendored Normal file
View File

@@ -0,0 +1,9 @@
# gRPC PHP Client Library
This repository contains only PHP files to support Composer installation.
This repository is a mirror of [gRPC](https://github.com/grpc/grpc). Any support
requests, bug reports, or development contributions should be directed to
that project.
To install gRPC for PHP, please see https://github.com/grpc/grpc/tree/master/src/php

24
vendor/grpc/grpc/composer.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"name": "grpc/grpc",
"type": "library",
"description": "gRPC library for PHP",
"keywords": ["rpc"],
"homepage": "https://grpc.io",
"license": "Apache-2.0",
"version": "1.74.0",
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"google/auth": "^v1.3.0"
},
"suggest": {
"ext-protobuf": "For better performance, install the protobuf C extension.",
"google/protobuf": "To get started using grpc quickly, install the native protobuf library."
},
"autoload": {
"psr-4": {
"Grpc\\": "src/lib/"
}
}
}

4337
vendor/grpc/grpc/etc/roots.pem vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,147 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Class AbstractCall.
* @package Grpc
*/
abstract class AbstractCall
{
/**
* @var Call
*/
protected $call;
protected $deserialize;
protected $metadata;
protected $trailing_metadata;
/**
* Create a new Call wrapper object.
*
* @param Channel $channel The channel to communicate on
* @param string $method The method to call on the
* remote server
* @param callback $deserialize A callback function to deserialize
* the response
* @param array $options Call options (optional)
*/
public function __construct(Channel $channel,
$method,
$deserialize,
array $options = [])
{
if (array_key_exists('timeout', $options) &&
is_numeric($timeout = $options['timeout'])
) {
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
} else {
$deadline = Timeval::infFuture();
}
$this->call = new Call($channel, $method, $deadline);
$this->deserialize = $deserialize;
$this->metadata = null;
$this->trailing_metadata = null;
if (array_key_exists('call_credentials_callback', $options) &&
is_callable($call_credentials_callback =
$options['call_credentials_callback'])
) {
$call_credentials = CallCredentials::createFromPlugin(
$call_credentials_callback
);
$this->call->setCredentials($call_credentials);
}
}
/**
* @return mixed The metadata sent by the server
*/
public function getMetadata()
{
return $this->metadata;
}
/**
* @return mixed The trailing metadata sent by the server
*/
public function getTrailingMetadata()
{
return $this->trailing_metadata;
}
/**
* @return string The URI of the endpoint
*/
public function getPeer()
{
return $this->call->getPeer();
}
/**
* Cancels the call.
*/
public function cancel()
{
$this->call->cancel();
}
/**
* Serialize a message to the protobuf binary format.
*
* @param mixed $data The Protobuf message
*
* @return string The protobuf binary format
*/
protected function _serializeMessage($data)
{
// Proto3 implementation
return $data->serializeToString();
}
/**
* Deserialize a response value to an object.
*
* @param string $value The binary value to deserialize
*
* @return mixed The deserialized value
*/
protected function _deserializeResponse($value)
{
if ($value === null) {
return;
}
list($className, $deserializeFunc) = $this->deserialize;
$obj = new $className();
$obj->mergeFromString($value);
return $obj;
}
/**
* Set the CallCredentials for the underlying Call.
*
* @param CallCredentials $call_credentials The CallCredentials object
*/
public function setCallCredentials($call_credentials)
{
$this->call->setCredentials($call_credentials);
}
}

618
vendor/grpc/grpc/src/lib/BaseStub.php vendored Normal file
View File

@@ -0,0 +1,618 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Base class for generated client stubs. Stub methods are expected to call
* _simpleRequest or _streamRequest and return the result.
*/
class BaseStub
{
private $hostname;
private $hostname_override;
private $channel;
private $call_invoker;
// a callback function
private $update_metadata;
/**
* @param string $hostname
* @param array $opts
* - 'update_metadata': (optional) a callback function which takes in a
* metadata array, and returns an updated metadata array
* - 'grpc.primary_user_agent': (optional) a user-agent string
* @param Channel|InterceptorChannel $channel An already created Channel or InterceptorChannel object (optional)
*/
public function __construct($hostname, $opts, $channel = null)
{
if (!method_exists('Grpc\ChannelCredentials', 'isDefaultRootsPemSet') ||
!ChannelCredentials::isDefaultRootsPemSet()) {
$ssl_roots = file_get_contents(
dirname(__FILE__).'/../../etc/roots.pem'
);
ChannelCredentials::setDefaultRootsPem($ssl_roots);
}
$this->hostname = $hostname;
$this->update_metadata = null;
if (isset($opts['update_metadata'])) {
if (is_callable($opts['update_metadata'])) {
$this->update_metadata = $opts['update_metadata'];
}
unset($opts['update_metadata']);
}
if (!empty($opts['grpc.ssl_target_name_override'])) {
$this->hostname_override = $opts['grpc.ssl_target_name_override'];
}
if (isset($opts['grpc_call_invoker'])) {
$this->call_invoker = $opts['grpc_call_invoker'];
unset($opts['grpc_call_invoker']);
$channel_opts = $this->updateOpts($opts);
// If the grpc_call_invoker is defined, use the channel created by the call invoker.
$this->channel = $this->call_invoker->createChannelFactory($hostname, $channel_opts);
return;
}
$this->call_invoker = new DefaultCallInvoker();
if ($channel) {
if (!is_a($channel, 'Grpc\Channel') &&
!is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
throw new \Exception('The channel argument is not a Channel object '.
'or an InterceptorChannel object created by '.
'Interceptor::intercept($channel, Interceptor|Interceptor[] $interceptors)');
}
$this->channel = $channel;
return;
}
$this->channel = static::getDefaultChannel($hostname, $opts);
}
private static function updateOpts($opts) {
if (!empty($opts['grpc.primary_user_agent'])) {
$opts['grpc.primary_user_agent'] .= ' ';
} else {
$opts['grpc.primary_user_agent'] = '';
}
if (defined('\Grpc\VERSION')) {
$version_str = \Grpc\VERSION;
} else {
if (!file_exists($composerFile = __DIR__.'/../../composer.json')) {
// for grpc/grpc-php subpackage
$composerFile = __DIR__.'/../composer.json';
}
$package_config = json_decode(file_get_contents($composerFile), true);
$version_str = $package_config['version'];
}
$opts['grpc.primary_user_agent'] .= 'grpc-php/'.$version_str;
if (!array_key_exists('credentials', $opts)) {
throw new \Exception("The opts['credentials'] key is now ".
'required. Please see one of the '.
'ChannelCredentials::create methods');
}
return $opts;
}
/**
* Creates and returns the default Channel
*
* @param array $opts Channel constructor options
*
* @return Channel The channel
*/
public static function getDefaultChannel($hostname, array $opts)
{
$channel_opts = self::updateOpts($opts);
return new Channel($hostname, $channel_opts);
}
/**
* @return string The URI of the endpoint
*/
public function getTarget()
{
return $this->channel->getTarget();
}
/**
* @param bool $try_to_connect (optional)
*
* @return int The grpc connectivity state
*/
public function getConnectivityState($try_to_connect = false)
{
return $this->channel->getConnectivityState($try_to_connect);
}
/**
* @param int $timeout in microseconds
*
* @return bool true if channel is ready
* @throws Exception if channel is in FATAL_ERROR state
*/
public function waitForReady($timeout)
{
$new_state = $this->getConnectivityState(true);
if ($this->_checkConnectivityState($new_state)) {
return true;
}
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
while ($this->channel->watchConnectivityState($new_state, $deadline)) {
// state has changed before deadline
$new_state = $this->getConnectivityState();
if ($this->_checkConnectivityState($new_state)) {
return true;
}
}
// deadline has passed
$new_state = $this->getConnectivityState();
return $this->_checkConnectivityState($new_state);
}
/**
* Close the communication channel associated with this stub.
*/
public function close()
{
$this->channel->close();
}
/**
* @param $new_state Connect state
*
* @return bool true if state is CHANNEL_READY
* @throws Exception if state is CHANNEL_FATAL_FAILURE
*/
private function _checkConnectivityState($new_state)
{
if ($new_state == \Grpc\CHANNEL_READY) {
return true;
}
if ($new_state == \Grpc\CHANNEL_FATAL_FAILURE) {
throw new \Exception('Failed to connect to server');
}
return false;
}
/**
* constructs the auth uri for the jwt.
*
* @param string $method The method string
*
* @return string The URL string
*/
private function _get_jwt_aud_uri($method)
{
// TODO(jtattermusch): This is not the correct implementation
// of extracting JWT "aud" claim. We should rely on
// grpc_metadata_credentials_plugin which
// also provides the correct value of "aud" claim
// in the grpc_auth_metadata_context.service_url field.
// Trying to do the construction of "aud" field ourselves
// is bad.
$last_slash_idx = strrpos($method, '/');
if ($last_slash_idx === false) {
throw new \InvalidArgumentException(
'service name must have a slash'
);
}
$service_name = substr($method, 0, $last_slash_idx);
if ($this->hostname_override) {
$hostname = $this->hostname_override;
} else {
$hostname = $this->hostname;
}
// Remove the port if it is 443
// See https://github.com/grpc/grpc/blob/07c9f7a36b2a0d34fcffebc85649cf3b8c339b5d/src/core/filter/auth/client_auth_filter.cc#L205
if ((strlen($hostname) > 4) && (substr($hostname, -4) === ":443")) {
$hostname = substr($hostname, 0, -4);
}
return 'https://'.$hostname.$service_name;
}
/**
* validate and normalize the metadata array.
*
* @param array $metadata The metadata map
*
* @return array $metadata Validated and key-normalized metadata map
* @throws InvalidArgumentException if key contains invalid characters
*/
private function _validate_and_normalize_metadata($metadata)
{
$metadata_copy = [];
foreach ($metadata as $key => $value) {
if (!preg_match('/^[.A-Za-z\d_-]+$/', $key)) {
throw new \InvalidArgumentException(
'Metadata keys must be nonempty strings containing only '.
'alphanumeric characters, hyphens, underscores and dots'
);
}
$metadata_copy[strtolower($key)] = $value;
}
return $metadata_copy;
}
/**
* Create a function which can be used to create UnaryCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _GrpcUnaryUnary($channel)
{
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->UnaryCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($argument, $metadata, $options);
return $call;
};
}
/**
* Create a function which can be used to create ServerStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _GrpcStreamUnary($channel)
{
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->ClientStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($metadata);
return $call;
};
}
/**
* Create a function which can be used to create ClientStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _GrpcUnaryStream($channel)
{
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->ServerStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($argument, $metadata, $options);
return $call;
};
}
/**
* Create a function which can be used to create BidiStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _GrpcStreamStream($channel)
{
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->BidiStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($metadata);
return $call;
};
}
/**
* Create a function which can be used to create UnaryCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _UnaryUnaryCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptUnaryUnary(
$method,
$argument,
$deserialize,
$this->_UnaryUnaryCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcUnaryUnary($channel);
}
/**
* Create a function which can be used to create ServerStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _UnaryStreamCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptUnaryStream(
$method,
$argument,
$deserialize,
$this->_UnaryStreamCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcUnaryStream($channel);
}
/**
* Create a function which can be used to create ClientStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _StreamUnaryCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptStreamUnary(
$method,
$deserialize,
$this->_StreamUnaryCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcStreamUnary($channel);
}
/**
* Create a function which can be used to create BidiStreamingCall
*
* @param Channel|InterceptorChannel $channel
* @param callable $deserialize A function that deserializes the response
*
* @return \Closure
*/
private function _StreamStreamCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptStreamStream(
$method,
$deserialize,
$this->_StreamStreamCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcStreamStream($channel);
}
/* This class is intended to be subclassed by generated code, so
* all functions begin with "_" to avoid name collisions. */
/**
* Call a remote method that takes a single argument and has a
* single output.
*
* @param string $method The name of the method to call
* @param mixed $argument The argument to the method
* @param callable $deserialize A function that deserializes the response
* @param array $metadata A metadata map to send to the server
* (optional)
* @param array $options An array of options (optional)
*
* @return UnaryCall The active call object
*/
protected function _simpleRequest(
$method,
$argument,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_UnaryUnaryCallFactory($this->channel);
$call = $call_factory($method, $argument, $deserialize, $metadata, $options);
return $call;
}
/**
* Call a remote method that takes a stream of arguments and has a single
* output.
*
* @param string $method The name of the method to call
* @param callable $deserialize A function that deserializes the response
* @param array $metadata A metadata map to send to the server
* (optional)
* @param array $options An array of options (optional)
*
* @return ClientStreamingCall The active call object
*/
protected function _clientStreamRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_StreamUnaryCallFactory($this->channel);
$call = $call_factory($method, $deserialize, $metadata, $options);
return $call;
}
/**
* Call a remote method that takes a single argument and returns a stream
* of responses.
*
* @param string $method The name of the method to call
* @param mixed $argument The argument to the method
* @param callable $deserialize A function that deserializes the responses
* @param array $metadata A metadata map to send to the server
* (optional)
* @param array $options An array of options (optional)
*
* @return ServerStreamingCall The active call object
*/
protected function _serverStreamRequest(
$method,
$argument,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_UnaryStreamCallFactory($this->channel);
$call = $call_factory($method, $argument, $deserialize, $metadata, $options);
return $call;
}
/**
* Call a remote method with messages streaming in both directions.
*
* @param string $method The name of the method to call
* @param callable $deserialize A function that deserializes the responses
* @param array $metadata A metadata map to send to the server
* (optional)
* @param array $options An array of options (optional)
*
* @return BidiStreamingCall The active call object
*/
protected function _bidiRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_StreamStreamCallFactory($this->channel);
$call = $call_factory($method, $deserialize, $metadata, $options);
return $call;
}
}

View File

@@ -0,0 +1,105 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Represents an active call that allows for sending and receiving messages
* in streams in any order.
*/
class BidiStreamingCall extends AbstractCall
{
/**
* Start the call.
*
* @param array $metadata Metadata to send with the call, if applicable
* (optional)
*/
public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
]);
}
/**
* Reads the next value from the server.
*
* @return mixed The next value from the server, or null if there is none
*/
public function read()
{
$batch = [OP_RECV_MESSAGE => true];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$read_event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $read_event->metadata;
}
return $this->_deserializeResponse($read_event->message);
}
/**
* Write a single message to the server. This cannot be called after
* writesDone is called.
*
* @param ByteBuffer $data The data to write
* @param array $options An array of options, possible keys:
* 'flags' => a number (optional)
*/
public function write($data, array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_MESSAGE => $message_array,
]);
}
/**
* Indicate that no more writes will be sent.
*/
public function writesDone()
{
$this->call->startBatch([
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
/**
* Wait for the server to send the status, and return it.
*
* @return \stdClass The status object, with integer $code, string
* $details, and array $metadata members
*/
public function getStatus()
{
$status_event = $this->call->startBatch([
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->trailing_metadata = $status_event->status->metadata;
return $status_event->status;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* CallInvoker is used to pass the self defined channel into the stub,
* while intercept each RPC with the channel accessible.
*/
interface CallInvoker
{
public function createChannelFactory($hostname, $opts);
public function UnaryCall($channel, $method, $deserialize, $options);
public function ClientStreamingCall($channel, $method, $deserialize, $options);
public function ServerStreamingCall($channel, $method, $deserialize, $options);
public function BidiStreamingCall($channel, $method, $deserialize, $options);
}

View File

@@ -0,0 +1,80 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Represents an active call that sends a stream of messages and then gets
* a single response.
*/
class ClientStreamingCall extends AbstractCall
{
/**
* Start the call.
*
* @param array $metadata Metadata to send with the call, if applicable
* (optional)
*/
public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
]);
}
/**
* Write a single message to the server. This cannot be called after
* wait is called.
*
* @param ByteBuffer $data The data to write
* @param array $options An array of options, possible keys:
* 'flags' => a number (optional)
*/
public function write($data, array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_MESSAGE => $message_array,
]);
}
/**
* Wait for the server to respond with data and a status.
*
* @return array [response data, status]
*/
public function wait()
{
$event = $this->call->startBatch([
OP_SEND_CLOSE_FROM_CLIENT => true,
OP_RECV_INITIAL_METADATA => true,
OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->metadata = $event->metadata;
$status = $event->status;
$this->trailing_metadata = $status->metadata;
return [$this->_deserializeResponse($event->message), $status];
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Default call invoker in the gRPC stub.
*/
class DefaultCallInvoker implements CallInvoker
{
public function createChannelFactory($hostname, $opts) {
return new Channel($hostname, $opts);
}
public function UnaryCall($channel, $method, $deserialize, $options) {
return new UnaryCall($channel, $method, $deserialize, $options);
}
public function ClientStreamingCall($channel, $method, $deserialize, $options) {
return new ClientStreamingCall($channel, $method, $deserialize, $options);
}
public function ServerStreamingCall($channel, $method, $deserialize, $options) {
return new ServerStreamingCall($channel, $method, $deserialize, $options);
}
public function BidiStreamingCall($channel, $method, $deserialize, $options) {
return new BidiStreamingCall($channel, $method, $deserialize, $options);
}
}

View File

@@ -0,0 +1,91 @@
<?php
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Represents an interceptor that intercept RPC invocations before call starts.
* There is one proposal related to the argument $deserialize under the review.
* The proposal link is https://github.com/grpc/proposal/pull/86.
*/
class Interceptor
{
public function interceptUnaryUnary(
$method,
$argument,
$deserialize,
$continuation,
array $metadata = [],
array $options = []
) {
return $continuation($method, $argument, $deserialize, $metadata, $options);
}
public function interceptStreamUnary(
$method,
$deserialize,
$continuation,
array $metadata = [],
array $options = []
) {
return $continuation($method, $deserialize, $metadata, $options);
}
public function interceptUnaryStream(
$method,
$argument,
$deserialize,
$continuation,
array $metadata = [],
array $options = []
) {
return $continuation($method, $argument, $deserialize, $metadata, $options);
}
public function interceptStreamStream(
$method,
$deserialize,
$continuation,
array $metadata = [],
array $options = []
) {
return $continuation($method, $deserialize, $metadata, $options);
}
/**
* Intercept the methods with Channel
*
* @param Channel|InterceptorChannel $channel An already created Channel or InterceptorChannel object (optional)
* @param Interceptor|Interceptor[] $interceptors interceptors to be added
*
* @return InterceptorChannel
*/
public static function intercept($channel, $interceptors)
{
if (is_array($interceptors)) {
for ($i = count($interceptors) - 1; $i >= 0; $i--) {
$channel = new Internal\InterceptorChannel($channel, $interceptors[$i]);
}
} else {
$channel = new Internal\InterceptorChannel($channel, $interceptors);
}
return $channel;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc\Internal;
/**
* This is a PRIVATE API and can change without notice.
*/
class InterceptorChannel extends \Grpc\Channel
{
private $next = null;
private $interceptor;
/**
* @param Channel|InterceptorChannel $channel An already created Channel
* or InterceptorChannel object (optional)
* @param Interceptor $interceptor
*/
public function __construct($channel, $interceptor)
{
if (!is_a($channel, 'Grpc\Channel') &&
!is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
throw new \Exception('The channel argument is not a Channel object '.
'or an InterceptorChannel object created by '.
'Interceptor::intercept($channel, Interceptor|Interceptor[] $interceptors)');
}
$this->interceptor = $interceptor;
$this->next = $channel;
}
public function getNext()
{
return $this->next;
}
public function getInterceptor()
{
return $this->interceptor;
}
public function getTarget()
{
return $this->getNext()->getTarget();
}
public function watchConnectivityState($new_state, $deadline)
{
return $this->getNext()->watchConnectivityState($new_state, $deadline);
}
public function getConnectivityState($try_to_connect = false)
{
return $this->getNext()->getConnectivityState($try_to_connect);
}
public function close()
{
return $this->getNext()->close();
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
class MethodDescriptor
{
public function __construct(
object $service,
string $method_name,
string $request_type,
int $call_type
) {
$this->service = $service;
$this->method_name = $method_name;
$this->request_type = $request_type;
$this->call_type = $call_type;
}
public const UNARY_CALL = 0;
public const SERVER_STREAMING_CALL = 1;
public const CLIENT_STREAMING_CALL = 2;
public const BIDI_STREAMING_CALL = 3;
public $service;
public $method_name;
public $request_type;
public $call_type;
}

151
vendor/grpc/grpc/src/lib/RpcServer.php vendored Normal file
View File

@@ -0,0 +1,151 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
/**
* Class RpcServer
* @package Grpc
*/
class RpcServer extends Server
{
// [ <String method_full_path> => MethodDescriptor ]
private $paths_map = [];
private function waitForNextEvent()
{
return $this->requestCall();
}
/**
* Add a service to this server
*
* @param Object $service The service to be added
*/
public function handle($service)
{
$methodDescriptors = $service->getMethodDescriptors();
$exist_methods = array_intersect_key($this->paths_map, $methodDescriptors);
if (!empty($exist_methods)) {
fwrite(STDERR, "WARNING: " . 'override already registered methods: ' .
implode(', ', array_keys($exist_methods)) . PHP_EOL);
}
$this->paths_map = array_merge($this->paths_map, $methodDescriptors);
return $this->paths_map;
}
public function run()
{
$this->start();
while (true) try {
// This blocks until the server receives a request
$event = $this->waitForNextEvent();
$full_path = $event->method;
$context = new ServerContext($event);
$server_writer = new ServerCallWriter($event->call, $context);
if (!array_key_exists($full_path, $this->paths_map)) {
$context->setStatus(Status::unimplemented());
$server_writer->finish();
continue;
};
$method_desc = $this->paths_map[$full_path];
$server_reader = new ServerCallReader(
$event->call,
$method_desc->request_type
);
try {
$this->processCall(
$method_desc,
$server_reader,
$server_writer,
$context
);
} catch (\Exception $e) {
$context->setStatus(Status::status(
STATUS_INTERNAL,
$e->getMessage()
));
$server_writer->finish();
}
} catch (\Exception $e) {
fwrite(STDERR, "ERROR: " . $e->getMessage() . PHP_EOL);
exit(1);
}
}
private function processCall(
MethodDescriptor $method_desc,
ServerCallReader $server_reader,
ServerCallWriter $server_writer,
ServerContext $context
) {
// Dispatch to actual server logic
switch ($method_desc->call_type) {
case MethodDescriptor::UNARY_CALL:
$request = $server_reader->read();
$response =
call_user_func(
array($method_desc->service, $method_desc->method_name),
$request ?? new $method_desc->request_type,
$context
);
$server_writer->finish($response);
break;
case MethodDescriptor::SERVER_STREAMING_CALL:
$request = $server_reader->read();
call_user_func(
array($method_desc->service, $method_desc->method_name),
$request ?? new $method_desc->request_type,
$server_writer,
$context
);
break;
case MethodDescriptor::CLIENT_STREAMING_CALL:
$response = call_user_func(
array($method_desc->service, $method_desc->method_name),
$server_reader,
$context
);
$server_writer->finish($response);
break;
case MethodDescriptor::BIDI_STREAMING_CALL:
call_user_func(
array($method_desc->service, $method_desc->method_name),
$server_reader,
$server_writer,
$context
);
break;
default:
throw new \Exception();
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
class ServerCallReader
{
public function __construct($call, string $request_type)
{
$this->call_ = $call;
$this->request_type_ = $request_type;
}
public function read()
{
$event = $this->call_->startBatch([
OP_RECV_MESSAGE => true,
]);
if ($event->message === null) {
return null;
}
$data = new $this->request_type_;
$data->mergeFromString($event->message);
return $data;
}
private $call_;
private $request_type_;
}

View File

@@ -0,0 +1,109 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
class ServerCallWriter
{
public function __construct($call, $serverContext)
{
$this->call_ = $call;
$this->serverContext_ = $serverContext;
}
public function start(
$data = null,
array $options = []
) {
$batch = [];
$this->addSendInitialMetadataOpIfNotSent(
$batch,
$this->serverContext_->initialMetadata()
);
$this->addSendMessageOpIfHasData($batch, $data, $options);
$this->call_->startBatch($batch);
}
public function write(
$data,
array $options = []
) {
$batch = [];
$this->addSendInitialMetadataOpIfNotSent(
$batch,
$this->serverContext_->initialMetadata()
);
$this->addSendMessageOpIfHasData($batch, $data, $options);
$this->call_->startBatch($batch);
}
public function finish(
$data = null,
array $options = []
) {
$batch = [
OP_SEND_STATUS_FROM_SERVER =>
$this->serverContext_->status() ?? Status::ok(),
OP_RECV_CLOSE_ON_SERVER => true,
];
$this->addSendInitialMetadataOpIfNotSent(
$batch,
$this->serverContext_->initialMetadata()
);
$this->addSendMessageOpIfHasData($batch, $data, $options);
$this->call_->startBatch($batch);
}
////////////////////////////
private function addSendInitialMetadataOpIfNotSent(
array &$batch,
?array $initialMetadata = null
) {
if (!$this->initialMetadataSent_) {
$batch[OP_SEND_INITIAL_METADATA] = $initialMetadata ?? [];
$this->initialMetadataSent_ = true;
}
}
private function addSendMessageOpIfHasData(
array &$batch,
$data = null,
array $options = []
) {
if ($data) {
$message_array = ['message' => $data->serializeToString()];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$batch[OP_SEND_MESSAGE] = $message_array;
}
}
private $call_;
private $initialMetadataSent_ = false;
private $serverContext_;
}

View File

@@ -0,0 +1,76 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
class ServerContext
{
public function __construct($event)
{
$this->event = $event;
}
public function clientMetadata()
{
return $this->event->metadata;
}
public function deadline()
{
return $this->event->absolute_deadline;
}
public function host()
{
return $this->event->host;
}
public function method()
{
return $this->event->method;
}
public function setInitialMetadata($initialMetadata)
{
$this->initialMetadata_ = $initialMetadata;
}
public function initialMetadata()
{
return $this->initialMetadata_;
}
public function setStatus($status)
{
$this->status_ = $status;
}
public function status()
{
return $this->status_;
}
private $event;
private $initialMetadata_;
private $status_;
}

View File

@@ -0,0 +1,100 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Represents an active call that sends a single message and then gets a
* stream of responses.
*/
class ServerStreamingCall extends AbstractCall
{
/**
* Start the call.
*
* @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* (optional)
* @param array $options An array of options, possible keys:
* 'flags' => a number (optional)
*/
public function start($data, array $metadata = [], array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_SEND_MESSAGE => $message_array,
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
/**
* @return mixed An iterator of response values
*/
public function responses()
{
$batch = [OP_RECV_MESSAGE => true];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$read_event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $read_event->metadata;
}
$response = $read_event->message;
while ($response !== null) {
yield $this->_deserializeResponse($response);
$response = $this->call->startBatch([
OP_RECV_MESSAGE => true,
])->message;
}
}
/**
* Wait for the server to send the status, and return it.
*
* @return \stdClass The status object, with integer $code, string
* $details, and array $metadata members
*/
public function getStatus()
{
$status_event = $this->call->startBatch([
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->trailing_metadata = $status_event->status->metadata;
return $status_event->status;
}
/**
* @return mixed The metadata sent by the server
*/
public function getMetadata()
{
if ($this->metadata === null) {
$event = $this->call->startBatch([OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
}
return $this->metadata;
}
}

55
vendor/grpc/grpc/src/lib/Status.php vendored Normal file
View File

@@ -0,0 +1,55 @@
<?php
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* This is an experimental and incomplete implementation of gRPC server
* for PHP. APIs are _definitely_ going to be changed.
*
* DO NOT USE in production.
*/
/**
* Class Status
* @package Grpc
*/
class Status
{
public static function status(int $code, string $details, ?array $metadata = null): array
{
$status = [
'code' => $code,
'details' => $details,
];
if ($metadata) {
$status['metadata'] = $metadata;
}
return $status;
}
public static function ok(?array $metadata = null): array
{
return Status::status(STATUS_OK, 'OK', $metadata);
}
public static function unimplemented(): array
{
return Status::status(STATUS_UNIMPLEMENTED, 'UNIMPLEMENTED');
}
}

87
vendor/grpc/grpc/src/lib/UnaryCall.php vendored Normal file
View File

@@ -0,0 +1,87 @@
<?php
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Grpc;
/**
* Represents an active call that sends a single message and then gets a
* single response.
*
* @template T of \Google\Protobuf\Internal\Message
*/
class UnaryCall extends AbstractCall
{
/**
* Start the call.
*
* @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* (optional)
* @param array $options An array of options, possible keys:
* 'flags' => a number (optional)
*/
public function start($data, array $metadata = [], array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_SEND_MESSAGE => $message_array,
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
/**
* Wait for the server to respond with data and a status.
*
* @return array{0: T|null, 1: \stdClass} [response data, status]
*/
public function wait()
{
$batch = [
OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true,
];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $event->metadata;
}
$status = $event->status;
$this->trailing_metadata = $status->metadata;
return [$this->_deserializeResponse($event->message), $status];
}
/**
* @return mixed The metadata sent by the server
*/
public function getMetadata()
{
if ($this->metadata === null) {
$event = $this->call->startBatch([OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
}
return $this->metadata;
}
}