• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20namespace Grpc\Internal;
21
22/**
23 * This is a PRIVATE API and can change without notice.
24 */
25class InterceptorChannel extends \Grpc\Channel
26{
27    private $next = null;
28    private $interceptor;
29
30    /**
31     * @param Channel|InterceptorChannel $channel An already created Channel
32     * or InterceptorChannel object (optional)
33     * @param Interceptor  $interceptor
34     */
35    public function __construct($channel, $interceptor)
36    {
37        if (!is_a($channel, 'Grpc\Channel') &&
38            !is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
39            throw new \Exception('The channel argument is not a Channel object '.
40                'or an InterceptorChannel object created by '.
41                'Interceptor::intercept($channel, Interceptor|Interceptor[] $interceptors)');
42        }
43        $this->interceptor = $interceptor;
44        $this->next = $channel;
45    }
46
47    public function getNext()
48    {
49        return $this->next;
50    }
51
52    public function getInterceptor()
53    {
54        return $this->interceptor;
55    }
56
57    public function getTarget()
58    {
59        return $this->getNext()->getTarget();
60    }
61
62    public function watchConnectivityState($new_state, $deadline)
63    {
64        return $this->getNext()->watchConnectivityState($new_state, $deadline);
65    }
66
67    public function getConnectivityState($try_to_connect = false)
68    {
69        return $this->getNext()->getConnectivityState($try_to_connect);
70    }
71
72    public function close()
73    {
74        return $this->getNext()->close();
75    }
76}
77