Exemplo n.º 1
0
 /**
  * @param Request $request
  *
  * @return string
  *
  * @throws EncodingException
  */
 private function getEncodedBody(Request $request)
 {
     $body = json_encode(['jsonrpc' => '2.0', 'method' => $request->getMethod(), 'params' => $request->getArguments(), 'id' => 1]);
     if (json_last_error() !== JSON_ERROR_NONE) {
         throw new EncodingException(sprintf('Unable to encode request: %s', json_last_error_msg()));
     }
     return $body;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function get(Request $request)
 {
     $method = $request->getMethod();
     if (!isset($this->callbacks[$method])) {
         throw new HandlingException(sprintf('Method "%s" is not registered', $method));
     }
     return $this->callbacks[$method];
 }
 /**
  * {@inheritdoc}
  */
 public function call(Identity $identity, Request $request)
 {
     $this->logger->debug('Call "%method%" to service "%service%"', ['service' => $identity->getName(), 'request_method' => $request->getMethod(), 'request_arguments' => $request->getArguments(), 'request_headers' => $request->getHeaders(), 'driver' => get_class($this->driver)]);
     $promise = $this->driver->call($identity, $request);
     return new Promise(function ($timeout) use($identity, $request, $promise) {
         $response = $promise->resolve($timeout);
         $this->logger->debug('Response from "%service%"', ['service' => $identity->getName(), 'request_method' => $request->getMethod(), 'response_value' => $response->getValue(), 'response_headers' => $response->getHeaders(), 'driver' => get_class($this->driver)]);
         return $response;
     });
 }
 public function testGetWithDecoration()
 {
     $request = new Request('foo');
     $inner = $this->getCallableMock(self::once(), function (Identity $identity, Request $request) {
         return sprintf('<inner request="%s" identity="%s">', $request->getMethod(), $identity->getName());
     });
     $this->innerRouter->expects(self::once())->method('get')->with($request)->willReturn($inner);
     $this->router->decorate($this->getCallableMock(self::once(), function ($callable) {
         return function (Identity $identity, Request $request) use($callable) {
             return '<outer>' . $callable($identity, $request) . '</outer>';
         };
     }));
     $callable = $this->router->get($request);
     $result = $callable(new Identity('baz'), $request);
     self::assertEquals('<outer><inner request="foo" identity="baz"></outer>', $result);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function call(RequestInterface $request)
 {
     $next = $this->next(0, true);
     return $next($this->identity, Request::cast($request));
 }
 /**
  * @param Request $request
  *
  * @return Message
  */
 protected function createRequest(Request $request)
 {
     $arguments = $request->getArguments();
     $encoded = $this->getEncoder()->encode($arguments);
     return new Message($encoded->getBody(), ['content-type' => $encoded->getType(), 'message-id' => uniqid('', true), 'timestamp' => time(), 'headers' => array_merge($request->getHeaders(), ['topic' => $request->getMethod()])]);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function broadcast(RequestInterface $request)
 {
     $this->broadcaster->broadcast(Request::cast($request));
     return $this;
 }
 public static function make($service, Request $request)
 {
     return new self(sprintf('Non of the existent bindings for service "%s" support "%s" request', $service, $request->getMethod()));
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function call(RequestInterface $request)
 {
     return $this->driver->call($this->identity, Request::cast($request));
 }
 /**
  * {@inheritdoc}
  */
 public function broadcast(Request $request)
 {
     $this->logger->debug('New broadcast "%method%"', ['request_method' => $request->getMethod(), 'request_arguments' => $request->getArguments(), 'request_headers' => $request->getHeaders(), 'broadcaster' => get_class($this->broadcaster)]);
     $this->broadcaster->broadcast($request);
 }
Exemplo n.º 11
0
 public function testCastInvalidRequest()
 {
     $this->expectException(\InvalidArgumentException::class);
     Request::cast(new InvalidRequest());
 }
Exemplo n.º 12
0
 /**
  * @param Request              $request
  * @param \ReflectionParameter $parameter
  *
  * @return mixed
  */
 public function getParameterValue(Request $request, \ReflectionParameter $parameter)
 {
     $args = $request->getArguments();
     $names = [$parameter->name, $this->getCamelCaseName($parameter->name), $this->getSneakCaseName($parameter->name)];
     foreach ($names as $name) {
         if (isset($args[$name])) {
             return $args[$name];
         }
     }
     return null;
 }