/**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (null === ($contents = $request->headers->get($this->headerName))) {
         return;
     }
     $this->storage->setRequestIdentifier(StringRequestIdentifier::fromString($contents));
 }
 function its_middleware_adds_the_header_to_the_request(RequestIdentifierResolver $resolver, RequestInterface $request)
 {
     $identifier = StringRequestIdentifier::fromString('1234');
     $resolver->get()->shouldBeCalled()->willReturn($identifier);
     $request->withAddedHeader('X-Request-Id', '1234')->shouldBeCalled();
     $middlewareFactory = $this->create();
     $middleware = $middlewareFactory(function () {
     });
     $middleware($request, []);
 }
 function it_stores_the_requests_identifier_if_in_the_request_headers(HttpKernelInterface $kernel, RequestIdentifierStorage $requestIdentifierStorage)
 {
     $event = new GetResponseEvent($kernel->getWrappedObject(), Request::create('/', 'GET', [], [], [], ['HTTP_X-Request-Identifier' => '12345']), HttpKernelInterface::MASTER_REQUEST);
     $requestIdentifierStorage->setRequestIdentifier(StringRequestIdentifier::fromString('12345'))->shouldBeCalled();
     $this->onKernelRequest($event);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     return StringRequestIdentifier::fromString(uniqid('ri'));
 }