@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | public function testSetSid() |
| 17 | 17 | { |
| 18 | - $this->http->setHandler(function () { |
|
| 18 | + $this->http->setHandler(function (){ |
|
| 19 | 19 | return ++$this->session()->getSection('cli')->value; |
| 20 | 20 | }); |
| 21 | 21 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function testSessionResume() |
| 31 | 31 | { |
| 32 | - $this->http->setHandler(function () { |
|
| 32 | + $this->http->setHandler(function (){ |
|
| 33 | 33 | return ++$this->session()->getSection('cli')->value; |
| 34 | 34 | }); |
| 35 | 35 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function testSessionRegenerateId() |
| 55 | 55 | { |
| 56 | - $this->http->setHandler(function () { |
|
| 56 | + $this->http->setHandler(function (){ |
|
| 57 | 57 | return ++$this->session()->getSection('cli')->value; |
| 58 | 58 | }); |
| 59 | 59 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $this->assertSame(200, $result->getStatusCode()); |
| 71 | 71 | $this->assertSame('2', $result->getBody()->__toString()); |
| 72 | 72 | |
| 73 | - $this->http->setHandler(function () { |
|
| 73 | + $this->http->setHandler(function (){ |
|
| 74 | 74 | $this->session()->regenerateID(false); |
| 75 | 75 | |
| 76 | 76 | return ++$this->session()->getSection('cli')->value; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | public function testDestroySession() |
| 91 | 91 | { |
| 92 | - $this->http->setHandler(function () { |
|
| 92 | + $this->http->setHandler(function (){ |
|
| 93 | 93 | return ++$this->session()->getSection('cli')->value; |
| 94 | 94 | }); |
| 95 | 95 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | ]); |
| 103 | 103 | $this->assertSame(200, $result->getStatusCode()); |
| 104 | 104 | $this->assertSame('2', $result->getBody()->__toString()); |
| 105 | - $this->http->setHandler(function () { |
|
| 105 | + $this->http->setHandler(function (){ |
|
| 106 | 106 | $this->session()->destroy(); |
| 107 | 107 | $this->assertFalse($this->session()->isStarted()); |
| 108 | 108 | |
@@ -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 | |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | |
| 47 | 47 | public function inputAction(InputScope $i) |
| 48 | 48 | { |
| 49 | - return 'value: ' . $i->withPrefix('section')->getValue('query', 'value'); |
|
| 49 | + return 'value: '.$i->withPrefix('section')->getValue('query', 'value'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function errorAction() |
@@ -120,15 +120,15 @@ |
||
| 120 | 120 | */ |
| 121 | 121 | private function getSession(): SessionInterface |
| 122 | 122 | { |
| 123 | - try { |
|
| 123 | + try{ |
|
| 124 | 124 | $request = $this->container->get(ServerRequestInterface::class); |
| 125 | 125 | $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE); |
| 126 | - if ($session === null) { |
|
| 126 | + if ($session === null){ |
|
| 127 | 127 | throw new ScopeException("Unable to receive active Session, invalid request scope"); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return $session; |
| 131 | - } catch (NotFoundExceptionInterface $e) { |
|
| 131 | + }catch (NotFoundExceptionInterface $e){ |
|
| 132 | 132 | throw new ScopeException("Unable to receive active session", $e->getCode(), $e); |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -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 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | CookiesConfig $cookiesConfig, |
| 58 | 58 | SessionFactory $factory, |
| 59 | 59 | ScopeInterface $scope |
| 60 | - ) { |
|
| 60 | + ){ |
|
| 61 | 61 | $this->config = $config; |
| 62 | 62 | $this->httpConfig = $httpConfig; |
| 63 | 63 | $this->cookiesConfig = $cookiesConfig; |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | $this->fetchID($request) |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - try { |
|
| 79 | + try{ |
|
| 80 | 80 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $session)); |
| 81 | - } catch (\Throwable $e) { |
|
| 81 | + }catch (\Throwable $e){ |
|
| 82 | 82 | $session->abort(); |
| 83 | 83 | throw $e; |
| 84 | 84 | } |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | Request $request, |
| 98 | 98 | Response $response |
| 99 | 99 | ): Response { |
| 100 | - if (!$session->isStarted()) { |
|
| 100 | + if (!$session->isStarted()){ |
|
| 101 | 101 | return $response; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $session->commit(); |
| 105 | 105 | |
| 106 | 106 | //SID changed |
| 107 | - if ($this->fetchID($request) != $session->getID()) { |
|
| 107 | + if ($this->fetchID($request) != $session->getID()){ |
|
| 108 | 108 | return $this->withCookie($request, $response, $session->getID()); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | protected function fetchID(Request $request): ?string |
| 122 | 122 | { |
| 123 | 123 | $cookies = $request->getCookieParams(); |
| 124 | - if (empty($cookies[$this->config->getCookie()])) { |
|
| 124 | + if (empty($cookies[$this->config->getCookie()])){ |
|
| 125 | 125 | return null; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | protected function clientSignature(Request $request): string |
| 155 | 155 | { |
| 156 | 156 | $signature = ''; |
| 157 | - foreach (static::SIGNATURE_HEADERS as $header) { |
|
| 158 | - $signature .= $request->getHeaderLine($header) . ';'; |
|
| 157 | + foreach (static::SIGNATURE_HEADERS as $header){ |
|
| 158 | + $signature .= $request->getHeaderLine($header).';'; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | return hash('sha256', $signature); |
@@ -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 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | string $domain = null, |
| 108 | 108 | bool $secure = null, |
| 109 | 109 | bool $httpOnly = true |
| 110 | - ) { |
|
| 110 | + ){ |
|
| 111 | 111 | $this->getCookieQueue()->set($name, $value, $lifetime, $path, $domain, $secure, $httpOnly); |
| 112 | 112 | |
| 113 | 113 | return $this; |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | private function getRequest(): ServerRequestInterface |
| 160 | 160 | { |
| 161 | - try { |
|
| 161 | + try{ |
|
| 162 | 162 | return $this->container->get(ServerRequestInterface::class); |
| 163 | - } catch (NotFoundExceptionInterface $e) { |
|
| 163 | + }catch (NotFoundExceptionInterface $e){ |
|
| 164 | 164 | throw new ScopeException("Unable to receive active request", $e->getCode(), $e); |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | { |
| 175 | 175 | $request = $this->getRequest(); |
| 176 | 176 | $queue = $request->getAttribute(CookieQueue::ATTRIBUTE, null); |
| 177 | - if ($queue === null) { |
|
| 177 | + if ($queue === null){ |
|
| 178 | 178 | throw new ScopeException("Unable to receive cookie queue, invalid request scope"); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -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,7 @@ |
||
| 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 | throw new ScopeException("Unable to resolve CookieQueue, invalid request scope"); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -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,7 @@ |
||
| 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 | throw new ScopeException("Unable to resolve Route, invalid request scope"); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -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 | |