Debian Codegraph @

src/php/lib/Grpc/Interceptor.php

raw
1 <?php
2 /*
3 *
4 * Copyright 2018 gRPC authors.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 namespace Grpc;
21
22 /**
23 * Represents an interceptor that intercept RPC invocations before call starts.
24 * There is one proposal related to the argument $deserialize under the review.
25 * The proposal link is https://github.com/grpc/proposal/pull/86.
26 */
27 class Interceptor
28 {
29 public function interceptUnaryUnary(
30 $method,
31 $argument,
32 $deserialize,
33 $continuation,
34 array $metadata = [],
35 array $options = []
36 ) {
37 return $continuation($method, $argument, $deserialize, $metadata, $options);
38 }
39
40 public function interceptStreamUnary(
41 $method,
42 $deserialize,
43 $continuation,
44 array $metadata = [],
45 array $options = []
46 ) {
47 return $continuation($method, $deserialize, $metadata, $options);
48 }
49
50 public function interceptUnaryStream(
51 $method,
52 $argument,
53 $deserialize,
54 $continuation,
55 array $metadata = [],
56 array $options = []
57 ) {
58 return $continuation($method, $argument, $deserialize, $metadata, $options);
59 }
60
61 public function interceptStreamStream(
62 $method,
63 $deserialize,
64 $continuation,
65 array $metadata = [],
66 array $options = []
67 ) {
68 return $continuation($method, $deserialize, $metadata, $options);
69 }
70
71 /**
72 * Intercept the methods with Channel
73 *
74 * @param Channel|InterceptorChannel $channel An already created Channel or InterceptorChannel object (optional)
75 * @param Interceptor|Interceptor[] $interceptors interceptors to be added
76 *
77 * @return InterceptorChannel
78 */
79 public static function intercept($channel, $interceptors)
80 {
81 if (is_array($interceptors)) {
82 for ($i = count($interceptors) - 1; $i >= 0; $i--) {
83 $channel = new Internal\InterceptorChannel($channel, $interceptors[$i]);
84 }
85 } else {
86 $channel = new Internal\InterceptorChannel($channel, $interceptors);
87 }
88 return $channel;
89 }
90 }
91