@@ -15,7 +15,8 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | public function testSetSid() |
| 17 | 17 | { |
| 18 | - $this->http->setHandler(function () { |
|
| 18 | + $this->http->setHandler(function () |
|
| 19 | + { |
|
| 19 | 20 | return ++$this->session()->getSection('cli')->value; |
| 20 | 21 | }); |
| 21 | 22 | |
@@ -29,7 +30,8 @@ discard block |
||
| 29 | 30 | |
| 30 | 31 | public function testSessionResume() |
| 31 | 32 | { |
| 32 | - $this->http->setHandler(function () { |
|
| 33 | + $this->http->setHandler(function () |
|
| 34 | + { |
|
| 33 | 35 | return ++$this->session()->getSection('cli')->value; |
| 34 | 36 | }); |
| 35 | 37 | |
@@ -53,7 +55,8 @@ discard block |
||
| 53 | 55 | |
| 54 | 56 | public function testSessionRegenerateId() |
| 55 | 57 | { |
| 56 | - $this->http->setHandler(function () { |
|
| 58 | + $this->http->setHandler(function () |
|
| 59 | + { |
|
| 57 | 60 | return ++$this->session()->getSection('cli')->value; |
| 58 | 61 | }); |
| 59 | 62 | |
@@ -70,7 +73,8 @@ discard block |
||
| 70 | 73 | $this->assertSame(200, $result->getStatusCode()); |
| 71 | 74 | $this->assertSame('2', $result->getBody()->__toString()); |
| 72 | 75 | |
| 73 | - $this->http->setHandler(function () { |
|
| 76 | + $this->http->setHandler(function () |
|
| 77 | + { |
|
| 74 | 78 | $this->session()->regenerateID(false); |
| 75 | 79 | |
| 76 | 80 | return ++$this->session()->getSection('cli')->value; |
@@ -89,7 +93,8 @@ discard block |
||
| 89 | 93 | |
| 90 | 94 | public function testDestroySession() |
| 91 | 95 | { |
| 92 | - $this->http->setHandler(function () { |
|
| 96 | + $this->http->setHandler(function () |
|
| 97 | + { |
|
| 93 | 98 | return ++$this->session()->getSection('cli')->value; |
| 94 | 99 | }); |
| 95 | 100 | |
@@ -102,7 +107,8 @@ discard block |
||
| 102 | 107 | ]); |
| 103 | 108 | $this->assertSame(200, $result->getStatusCode()); |
| 104 | 109 | $this->assertSame('2', $result->getBody()->__toString()); |
| 105 | - $this->http->setHandler(function () { |
|
| 110 | + $this->http->setHandler(function () |
|
| 111 | + { |
|
| 106 | 112 | $this->session()->destroy(); |
| 107 | 113 | $this->assertFalse($this->session()->isStarted()); |
| 108 | 114 | |
@@ -120,15 +120,19 @@ |
||
| 120 | 120 | */ |
| 121 | 121 | private function getSession(): SessionInterface |
| 122 | 122 | { |
| 123 | - try { |
|
| 123 | + try |
|
| 124 | + { |
|
| 124 | 125 | $request = $this->container->get(ServerRequestInterface::class); |
| 125 | 126 | $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE); |
| 126 | - if ($session === null) { |
|
| 127 | + if ($session === null) |
|
| 128 | + { |
|
| 127 | 129 | throw new ScopeException("Unable to receive active Session, invalid request scope"); |
| 128 | 130 | } |
| 129 | 131 | |
| 130 | 132 | return $session; |
| 131 | - } catch (NotFoundExceptionInterface $e) { |
|
| 133 | + } |
|
| 134 | + catch (NotFoundExceptionInterface $e) |
|
| 135 | + { |
|
| 132 | 136 | throw new ScopeException("Unable to receive active session", $e->getCode(), $e); |
| 133 | 137 | } |
| 134 | 138 | } |
@@ -76,9 +76,12 @@ discard block |
||
| 76 | 76 | $this->fetchID($request) |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - try { |
|
| 79 | + try |
|
| 80 | + { |
|
| 80 | 81 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $session)); |
| 81 | - } catch (\Throwable $e) { |
|
| 82 | + } |
|
| 83 | + catch (\Throwable $e) |
|
| 84 | + { |
|
| 82 | 85 | $session->abort(); |
| 83 | 86 | throw $e; |
| 84 | 87 | } |
@@ -97,14 +100,16 @@ discard block |
||
| 97 | 100 | Request $request, |
| 98 | 101 | Response $response |
| 99 | 102 | ): Response { |
| 100 | - if (!$session->isStarted()) { |
|
| 103 | + if (!$session->isStarted()) |
|
| 104 | + { |
|
| 101 | 105 | return $response; |
| 102 | 106 | } |
| 103 | 107 | |
| 104 | 108 | $session->commit(); |
| 105 | 109 | |
| 106 | 110 | //SID changed |
| 107 | - if ($this->fetchID($request) != $session->getID()) { |
|
| 111 | + if ($this->fetchID($request) != $session->getID()) |
|
| 112 | + { |
|
| 108 | 113 | return $this->withCookie($request, $response, $session->getID()); |
| 109 | 114 | } |
| 110 | 115 | |
@@ -121,7 +126,8 @@ discard block |
||
| 121 | 126 | protected function fetchID(Request $request): ?string |
| 122 | 127 | { |
| 123 | 128 | $cookies = $request->getCookieParams(); |
| 124 | - if (empty($cookies[$this->config->getCookie()])) { |
|
| 129 | + if (empty($cookies[$this->config->getCookie()])) |
|
| 130 | + { |
|
| 125 | 131 | return null; |
| 126 | 132 | } |
| 127 | 133 | |
@@ -154,7 +160,8 @@ discard block |
||
| 154 | 160 | protected function clientSignature(Request $request): string |
| 155 | 161 | { |
| 156 | 162 | $signature = ''; |
| 157 | - foreach (static::SIGNATURE_HEADERS as $header) { |
|
| 163 | + foreach (static::SIGNATURE_HEADERS as $header) |
|
| 164 | + { |
|
| 158 | 165 | $signature .= $request->getHeaderLine($header) . ';'; |
| 159 | 166 | } |
| 160 | 167 | |
@@ -158,9 +158,12 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | private function getRequest(): ServerRequestInterface |
| 160 | 160 | { |
| 161 | - try { |
|
| 161 | + try |
|
| 162 | + { |
|
| 162 | 163 | return $this->container->get(ServerRequestInterface::class); |
| 163 | - } catch (NotFoundExceptionInterface $e) { |
|
| 164 | + } |
|
| 165 | + catch (NotFoundExceptionInterface $e) |
|
| 166 | + { |
|
| 164 | 167 | throw new ScopeException("Unable to receive active request", $e->getCode(), $e); |
| 165 | 168 | } |
| 166 | 169 | } |
@@ -174,7 +177,8 @@ discard block |
||
| 174 | 177 | { |
| 175 | 178 | $request = $this->getRequest(); |
| 176 | 179 | $queue = $request->getAttribute(CookieQueue::ATTRIBUTE, null); |
| 177 | - if ($queue === null) { |
|
| 180 | + if ($queue === null) |
|
| 181 | + { |
|
| 178 | 182 | throw new ScopeException("Unable to receive cookie queue, invalid request scope"); |
| 179 | 183 | } |
| 180 | 184 | |
@@ -71,7 +71,8 @@ |
||
| 71 | 71 | private function cookieQueue(ServerRequestInterface $request): CookieQueue |
| 72 | 72 | { |
| 73 | 73 | $cookieQueue = $request->getAttribute(CookieQueue::ATTRIBUTE, null); |
| 74 | - if ($cookieQueue === null) { |
|
| 74 | + if ($cookieQueue === null) |
|
| 75 | + { |
|
| 75 | 76 | throw new ScopeException("Unable to resolve CookieQueue, invalid request scope"); |
| 76 | 77 | } |
| 77 | 78 | |
@@ -56,7 +56,8 @@ |
||
| 56 | 56 | private function route(ServerRequestInterface $request): RouteInterface |
| 57 | 57 | { |
| 58 | 58 | $route = $request->getAttribute(Router::ROUTE_ATTRIBUTE, null); |
| 59 | - if ($route === null) { |
|
| 59 | + if ($route === null) |
|
| 60 | + { |
|
| 60 | 61 | throw new ScopeException("Unable to resolve Route, invalid request scope"); |
| 61 | 62 | } |
| 62 | 63 | |