1515 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1616 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717 */
18- declare (strict_types = 1 );
18+ declare (strict_types= 1 );
1919
2020namespace Grphp \Client \Interceptors ;
2121
3131abstract class Base
3232{
3333 /** @var array */
34- protected $ options = [];
34+ protected array $ options = [];
3535 /** @var Message */
3636 protected $ request ;
3737 /** @var string */
38- protected $ method ;
38+ protected string $ method ;
3939 /** @var array */
40- protected $ metadata = [];
40+ protected array $ metadata = [];
4141 /** @var BaseStub */
4242 protected $ stub ;
4343
@@ -72,6 +72,47 @@ public function setRequest(&$request)
7272 $ this ->request = $ request ;
7373 }
7474
75+ /**
76+ * Gets the fully qualified method name, e.g. grphp.catalog.products/GetProduct
77+ *
78+ * @return string
79+ * @throws StubNotFoundException
80+ */
81+ public function getFullyQualifiedMethodName (): string
82+ {
83+ $ methodName = $ this ->getMethod ();
84+ $ stub = $ this ->getStub ();
85+ if (empty ($ stub )) {
86+ throw new StubNotFoundException ("Stub not found for $ methodName " );
87+ }
88+
89+ return $ stub ->getServiceName () . '/ ' . ucfirst ($ methodName );
90+ }
91+
92+ /**
93+ * Get the expected response protobuf message class
94+ *
95+ * @return string
96+ * @throws StubNotFoundException
97+ * @throws ResponseMessageLookupFailedException
98+ */
99+ public function getExpectedResponseMessageClass (): string
100+ {
101+ $ methodName = $ this ->getMethod ();
102+ $ stub = $ this ->getStub ();
103+ if (empty ($ stub )) {
104+ throw new StubNotFoundException ("Stub not found for $ methodName " );
105+ }
106+
107+ $ responseMessages = $ stub ->getExpectedResponseMessages ();
108+ $ methodName = lcfirst ($ methodName );
109+
110+ if (!array_key_exists ($ methodName , $ responseMessages )) {
111+ throw new ResponseMessageLookupFailedException ();
112+ }
113+ return $ responseMessages [$ methodName ];
114+ }
115+
75116 /**
76117 * @return string
77118 */
@@ -84,7 +125,7 @@ public function getMethod(): string
84125 * @param string $method
85126 * @return void
86127 */
87- public function setMethod (string &$ method )
128+ public function setMethod (string &$ method ): void
88129 {
89130 $ this ->method = $ method ;
90131 }
@@ -101,7 +142,7 @@ public function getMetadata(): array
101142 * @param array $metadata
102143 * @return void
103144 */
104- public function setMetadata (array &$ metadata = [])
145+ public function setMetadata (array &$ metadata = []): void
105146 {
106147 $ this ->metadata = $ metadata ;
107148 }
@@ -118,7 +159,7 @@ public function getOptions(): array
118159 * @param array $options
119160 * @return void
120161 */
121- public function setOptions (array &$ options = [])
162+ public function setOptions (array &$ options = []): void
122163 {
123164 $ this ->options = $ options ;
124165 }
@@ -136,13 +177,13 @@ public function getOption(string $k, $default = null)
136177 /**
137178 * @return BaseStub
138179 */
139- public function getStub (): BaseStub
180+ public function getStub (): ? BaseStub
140181 {
141182 return $ this ->stub ;
142183 }
143184
144185 /**
145- * @param $stub
186+ * @param BaseStub $stub
146187 */
147188 public function setStub (BaseStub &$ stub )
148189 {
0 commit comments