/**
  * @param string     $method
  * @param string     $uri
  * @param array|null $parameters
  * @param array|null $sessionData
  *
  * @return ResponseInterface
  *
  * @throws \BadMethodCallException
  * @throws \Interop\Container\Exception\NotFoundException
  * @throws \Interop\Container\Exception\ContainerException
  * @throws \InvalidArgumentException
  */
 protected function handleRequest(string $method, string $uri, array $parameters = null, array $sessionData = null) : ResponseInterface
 {
     // Create request
     $request = (new ServerRequest())->withMethod($method)->withUri(new Uri($uri));
     // Set post parameters
     if ($parameters !== null) {
         $request = $request->withParsedBody($parameters);
     }
     // Set PSR-7 session data
     if ($sessionData !== null) {
         // Get session middleware
         $sessionMiddleWare = self::$container->get(SessionMiddleware::class);
         // Get signer
         $signerReflection = new \ReflectionProperty($sessionMiddleWare, 'signer');
         $signerReflection->setAccessible(true);
         $signer = $signerReflection->getValue($sessionMiddleWare);
         // Get signature key
         $signatureKeyReflection = new \ReflectionProperty($sessionMiddleWare, 'signatureKey');
         $signatureKeyReflection->setAccessible(true);
         $signatureKey = $signatureKeyReflection->getValue($sessionMiddleWare);
         // Set session data as a cookie
         $request = $request->withCookieParams([SessionMiddleware::DEFAULT_COOKIE => (string) (new Builder())->setIssuedAt((new \DateTime('-30 second'))->getTimestamp())->setExpiration((new \DateTime('+30 second'))->getTimestamp())->set(SessionMiddleware::SESSION_CLAIM, DefaultSessionData::fromTokenData($sessionData))->sign($signer, $signatureKey)->getToken()]);
     }
     // Invoke the request
     return self::$app->__invoke($request, new Response());
 }
 /**
  * @param SessionMiddleware $middleware
  * @param \DateTime $issuedAt
  * @param \DateTime $expiration
  *
  * @return string
  */
 private function createToken(SessionMiddleware $middleware, \DateTime $issuedAt, \DateTime $expiration) : string
 {
     return (string) (new Builder())->setIssuedAt($issuedAt->getTimestamp())->setExpiration($expiration->getTimestamp())->set(SessionMiddleware::SESSION_CLAIM, DefaultSessionData::fromTokenData(['foo' => 'bar']))->sign($this->getSigner($middleware), $this->getSignatureKey($middleware))->getToken();
 }
 /**
  * @dataProvider storageNonScalarDataProvider
  */
 public function testContainerStoresScalarValueFromNestedObjects($nonScalar, $expectedScalar)
 {
     $session = DefaultSessionData::fromTokenData(['key' => $nonScalar]);
     self::assertSame($expectedScalar, $session->get('key'));
     $session->set('otherKey', $nonScalar);
     self::assertSame($expectedScalar, $session->get('otherKey'));
 }