@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | $http = $this->container->get(Http::class); |
| 63 | 63 | $emitter = $emitter ?? $this->container->get(EmitterInterface::class); |
| 64 | 64 | |
| 65 | - try { |
|
| 65 | + try{ |
|
| 66 | 66 | $response = $http->handle($this->initRequest()); |
| 67 | 67 | $emitter->emit($response); |
| 68 | - } catch (\Throwable $e) { |
|
| 68 | + }catch (\Throwable $e){ |
|
| 69 | 69 | $this->handleException($emitter, $e); |
| 70 | - } finally { |
|
| 70 | + }finally{ |
|
| 71 | 71 | $this->finalizer->finalize(false); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | $handler = new HtmlHandler(); |
| 90 | 90 | |
| 91 | - try { |
|
| 91 | + try{ |
|
| 92 | 92 | /** @var SnapshotInterface $snapshot */ |
| 93 | 93 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 94 | 94 | |
| 95 | 95 | // on demand |
| 96 | 96 | $state = $this->container->get(StateInterface::class); |
| 97 | - if ($state !== null) { |
|
| 97 | + if ($state !== null){ |
|
| 98 | 98 | $handler = $handler->withState($state); |
| 99 | 99 | } |
| 100 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 100 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 101 | 101 | // nothing to report |
| 102 | 102 | } |
| 103 | 103 | |
@@ -62,12 +62,17 @@ discard block |
||
| 62 | 62 | $http = $this->container->get(Http::class); |
| 63 | 63 | $emitter = $emitter ?? $this->container->get(EmitterInterface::class); |
| 64 | 64 | |
| 65 | - try { |
|
| 65 | + try |
|
| 66 | + { |
|
| 66 | 67 | $response = $http->handle($this->initRequest()); |
| 67 | 68 | $emitter->emit($response); |
| 68 | - } catch (\Throwable $e) { |
|
| 69 | + } |
|
| 70 | + catch (\Throwable $e) |
|
| 71 | + { |
|
| 69 | 72 | $this->handleException($emitter, $e); |
| 70 | - } finally { |
|
| 73 | + } |
|
| 74 | + finally |
|
| 75 | + { |
|
| 71 | 76 | $this->finalizer->finalize(false); |
| 72 | 77 | } |
| 73 | 78 | } |
@@ -88,16 +93,20 @@ discard block |
||
| 88 | 93 | { |
| 89 | 94 | $handler = new HtmlHandler(); |
| 90 | 95 | |
| 91 | - try { |
|
| 96 | + try |
|
| 97 | + { |
|
| 92 | 98 | /** @var SnapshotInterface $snapshot */ |
| 93 | 99 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 94 | 100 | |
| 95 | 101 | // on demand |
| 96 | 102 | $state = $this->container->get(StateInterface::class); |
| 97 | - if ($state !== null) { |
|
| 103 | + if ($state !== null) |
|
| 104 | + { |
|
| 98 | 105 | $handler = $handler->withState($state); |
| 99 | 106 | } |
| 100 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 107 | + } |
|
| 108 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 109 | + { |
|
| 101 | 110 | // nothing to report |
| 102 | 111 | } |
| 103 | 112 | |
@@ -46,9 +46,9 @@ |
||
| 46 | 46 | DirectoriesInterface $dirs, |
| 47 | 47 | FilesInterface $files, |
| 48 | 48 | LoggerInterface $logger = null |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | return new FileSnapshooter( |
| 51 | - $dirs->get('runtime') . '/snapshots/', |
|
| 51 | + $dirs->get('runtime').'/snapshots/', |
|
| 52 | 52 | $env->get('SNAPSHOT_MAX_FILES', self::MAX_SNAPSHOTS), |
| 53 | 53 | $env->get('SNAPSHOT_VERBOSITY', HandlerInterface::VERBOSITY_VERBOSE), |
| 54 | 54 | new PlainHandler(), |
@@ -40,9 +40,9 @@ |
||
| 40 | 40 | public function renderException(Request $request, int $code, string $message): Response |
| 41 | 41 | { |
| 42 | 42 | $response = $this->responseFactory->createResponse($code); |
| 43 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 43 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
| 44 | 44 | $response->getBody()->write(json_encode(['status' => $code, 'error' => $message])); |
| 45 | - } else { |
|
| 45 | + }else{ |
|
| 46 | 46 | $response->getBody()->write("Error code: {$code}"); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -40,9 +40,12 @@ |
||
| 40 | 40 | public function renderException(Request $request, int $code, string $message): Response |
| 41 | 41 | { |
| 42 | 42 | $response = $this->responseFactory->createResponse($code); |
| 43 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 43 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
| 44 | + { |
|
| 44 | 45 | $response->getBody()->write(json_encode(['status' => $code, 'error' => $message])); |
| 45 | - } else { |
|
| 46 | + } |
|
| 47 | + else |
|
| 48 | + { |
|
| 46 | 49 | $response->getBody()->write("Error code: {$code}"); |
| 47 | 50 | } |
| 48 | 51 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function testAllowServerAccess(): void |
| 40 | 40 | { |
| 41 | - $this->init(static function () { |
|
| 41 | + $this->init(static function (){ |
|
| 42 | 42 | return true; |
| 43 | 43 | }); |
| 44 | 44 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | public function testDenyServerAccess(): void |
| 52 | 52 | { |
| 53 | - $this->init(static function () { |
|
| 53 | + $this->init(static function (){ |
|
| 54 | 54 | return false; |
| 55 | 55 | }); |
| 56 | 56 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | public function testServerAccessWithDependency(): void |
| 64 | 64 | { |
| 65 | - $this->init(static function (ServerRequestInterface $request) { |
|
| 65 | + $this->init(static function (ServerRequestInterface $request){ |
|
| 66 | 66 | return $request instanceof ServerRequestInterface; |
| 67 | 67 | }); |
| 68 | 68 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function testTopicAccessOK(): void |
| 126 | 126 | { |
| 127 | - $this->init(null, function () { |
|
| 127 | + $this->init(null, function (){ |
|
| 128 | 128 | return true; |
| 129 | 129 | }); |
| 130 | 130 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | public function testTopicWildcardAccessFail(): void |
| 138 | 138 | { |
| 139 | - $this->init(null, function () { |
|
| 139 | + $this->init(null, function (){ |
|
| 140 | 140 | return true; |
| 141 | 141 | }); |
| 142 | 142 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $this->init( |
| 152 | 152 | null, |
| 153 | 153 | null, |
| 154 | - function () { |
|
| 154 | + function (){ |
|
| 155 | 155 | return true; |
| 156 | 156 | } |
| 157 | 157 | ); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $this->init( |
| 168 | 168 | null, |
| 169 | 169 | null, |
| 170 | - function ($id) { |
|
| 170 | + function ($id){ |
|
| 171 | 171 | return $id === '1'; |
| 172 | 172 | } |
| 173 | 173 | ); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $this->init( |
| 184 | 184 | null, |
| 185 | 185 | null, |
| 186 | - function ($id) { |
|
| 186 | + function ($id){ |
|
| 187 | 187 | return $id === '1'; |
| 188 | 188 | } |
| 189 | 189 | ); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | 'CYCLE_AUTH' => true, |
| 205 | 205 | 'RR_BROADCAST_PATH' => '/ws/', |
| 206 | 206 | 'WS_SERVER_CALLBACK' => null, |
| 207 | - 'WS_TOPIC_CALLBACK' => function (AuthContextInterface $authContext) { |
|
| 207 | + 'WS_TOPIC_CALLBACK' => function (AuthContextInterface $authContext){ |
|
| 208 | 208 | return $authContext->getToken() !== null; |
| 209 | 209 | }, |
| 210 | 210 | 'WS_TOPIC_WILDCARD_CALLBACK' => null, |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function testAllowServerAccess(): void |
| 40 | 40 | { |
| 41 | - $this->init(static function () { |
|
| 41 | + $this->init(static function () |
|
| 42 | + { |
|
| 42 | 43 | return true; |
| 43 | 44 | }); |
| 44 | 45 | |
@@ -50,7 +51,8 @@ discard block |
||
| 50 | 51 | |
| 51 | 52 | public function testDenyServerAccess(): void |
| 52 | 53 | { |
| 53 | - $this->init(static function () { |
|
| 54 | + $this->init(static function () |
|
| 55 | + { |
|
| 54 | 56 | return false; |
| 55 | 57 | }); |
| 56 | 58 | |
@@ -62,7 +64,8 @@ discard block |
||
| 62 | 64 | |
| 63 | 65 | public function testServerAccessWithDependency(): void |
| 64 | 66 | { |
| 65 | - $this->init(static function (ServerRequestInterface $request) { |
|
| 67 | + $this->init(static function (ServerRequestInterface $request) |
|
| 68 | + { |
|
| 66 | 69 | return $request instanceof ServerRequestInterface; |
| 67 | 70 | }); |
| 68 | 71 | |
@@ -124,7 +127,8 @@ discard block |
||
| 124 | 127 | |
| 125 | 128 | public function testTopicAccessOK(): void |
| 126 | 129 | { |
| 127 | - $this->init(null, function () { |
|
| 130 | + $this->init(null, function () |
|
| 131 | + { |
|
| 128 | 132 | return true; |
| 129 | 133 | }); |
| 130 | 134 | |
@@ -136,7 +140,8 @@ discard block |
||
| 136 | 140 | |
| 137 | 141 | public function testTopicWildcardAccessFail(): void |
| 138 | 142 | { |
| 139 | - $this->init(null, function () { |
|
| 143 | + $this->init(null, function () |
|
| 144 | + { |
|
| 140 | 145 | return true; |
| 141 | 146 | }); |
| 142 | 147 | |
@@ -151,7 +156,8 @@ discard block |
||
| 151 | 156 | $this->init( |
| 152 | 157 | null, |
| 153 | 158 | null, |
| 154 | - function () { |
|
| 159 | + function () |
|
| 160 | + { |
|
| 155 | 161 | return true; |
| 156 | 162 | } |
| 157 | 163 | ); |
@@ -167,7 +173,8 @@ discard block |
||
| 167 | 173 | $this->init( |
| 168 | 174 | null, |
| 169 | 175 | null, |
| 170 | - function ($id) { |
|
| 176 | + function ($id) |
|
| 177 | + { |
|
| 171 | 178 | return $id === '1'; |
| 172 | 179 | } |
| 173 | 180 | ); |
@@ -183,7 +190,8 @@ discard block |
||
| 183 | 190 | $this->init( |
| 184 | 191 | null, |
| 185 | 192 | null, |
| 186 | - function ($id) { |
|
| 193 | + function ($id) |
|
| 194 | + { |
|
| 187 | 195 | return $id === '1'; |
| 188 | 196 | } |
| 189 | 197 | ); |
@@ -204,7 +212,8 @@ discard block |
||
| 204 | 212 | 'CYCLE_AUTH' => true, |
| 205 | 213 | 'RR_BROADCAST_PATH' => '/ws/', |
| 206 | 214 | 'WS_SERVER_CALLBACK' => null, |
| 207 | - 'WS_TOPIC_CALLBACK' => function (AuthContextInterface $authContext) { |
|
| 215 | + 'WS_TOPIC_CALLBACK' => function (AuthContextInterface $authContext) |
|
| 216 | + { |
|
| 208 | 217 | return $authContext->getToken() !== null; |
| 209 | 218 | }, |
| 210 | 219 | 'WS_TOPIC_WILDCARD_CALLBACK' => null, |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | array $headers = [] |
| 46 | 46 | ): ResponseInterface { |
| 47 | 47 | $r = $this->request($uri, 'GET', [], $headers, []); |
| 48 | - foreach ($attributes as $k => $v) { |
|
| 48 | + foreach ($attributes as $k => $v){ |
|
| 49 | 49 | $r = $r->withAttribute($k, $v); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | protected function fetchCookies(array $header) |
| 87 | 87 | { |
| 88 | 88 | $result = []; |
| 89 | - foreach ($header as $line) { |
|
| 89 | + foreach ($header as $line){ |
|
| 90 | 90 | $cookie = explode('=', $line); |
| 91 | 91 | $result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';'))); |
| 92 | 92 | } |
@@ -45,7 +45,8 @@ discard block |
||
| 45 | 45 | array $headers = [] |
| 46 | 46 | ): ResponseInterface { |
| 47 | 47 | $r = $this->request($uri, 'GET', [], $headers, []); |
| 48 | - foreach ($attributes as $k => $v) { |
|
| 48 | + foreach ($attributes as $k => $v) |
|
| 49 | + { |
|
| 49 | 50 | $r = $r->withAttribute($k, $v); |
| 50 | 51 | } |
| 51 | 52 | |
@@ -86,7 +87,8 @@ discard block |
||
| 86 | 87 | protected function fetchCookies(array $header) |
| 87 | 88 | { |
| 88 | 89 | $result = []; |
| 89 | - foreach ($header as $line) { |
|
| 90 | + foreach ($header as $line) |
|
| 91 | + { |
|
| 90 | 92 | $cookie = explode('=', $line); |
| 91 | 93 | $result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';'))); |
| 92 | 94 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | ScopeInterface $scope, |
| 51 | 51 | ResolverInterface $resolver, |
| 52 | 52 | ResponseFactoryInterface $responseFactory |
| 53 | - ) { |
|
| 53 | + ){ |
|
| 54 | 54 | $this->config = $config; |
| 55 | 55 | $this->scope = $scope; |
| 56 | 56 | $this->resolver = $resolver; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 69 | 69 | { |
| 70 | - if ($request->getUri()->getPath() !== $this->config->getPath()) { |
|
| 70 | + if ($request->getUri()->getPath() !== $this->config->getPath()){ |
|
| 71 | 71 | return $handler->handle($request); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // server authorization |
| 75 | - if ($request->getAttribute('ws:joinServer', null) !== null) { |
|
| 76 | - if (!$this->authorizeServer($request)) { |
|
| 75 | + if ($request->getAttribute('ws:joinServer', null) !== null){ |
|
| 76 | + if (!$this->authorizeServer($request)){ |
|
| 77 | 77 | return $this->responseFactory->createResponse(403); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // topic authorization |
| 84 | - if (is_string($request->getAttribute('ws:joinTopics', null))) { |
|
| 84 | + if (is_string($request->getAttribute('ws:joinTopics', null))){ |
|
| 85 | 85 | $topics = explode(',', $request->getAttribute('ws:joinTopics')); |
| 86 | - foreach ($topics as $topic) { |
|
| 87 | - if (!$this->authorizeTopic($request, $topic)) { |
|
| 86 | + foreach ($topics as $topic){ |
|
| 87 | + if (!$this->authorizeTopic($request, $topic)){ |
|
| 88 | 88 | return $this->responseFactory->createResponse(403); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | private function authorizeServer(ServerRequestInterface $request): bool |
| 105 | 105 | { |
| 106 | 106 | $callback = $this->config->getServerCallback(); |
| 107 | - if ($callback === null) { |
|
| 107 | + if ($callback === null){ |
|
| 108 | 108 | return true; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $parameters = []; |
| 124 | 124 | $callback = $this->config->findTopicCallback($topic, $parameters); |
| 125 | - if ($callback === null) { |
|
| 125 | + if ($callback === null){ |
|
| 126 | 126 | return false; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | /** @var \ReflectionFunctionAbstract $reflection */ |
| 143 | 143 | $reflection = null; |
| 144 | - switch (true) { |
|
| 144 | + switch (true){ |
|
| 145 | 145 | case $callback instanceof \Closure || is_string($callback): |
| 146 | 146 | $reflection = new \ReflectionFunction($callback); |
| 147 | 147 | break; |
@@ -67,13 +67,16 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 69 | 69 | { |
| 70 | - if ($request->getUri()->getPath() !== $this->config->getPath()) { |
|
| 70 | + if ($request->getUri()->getPath() !== $this->config->getPath()) |
|
| 71 | + { |
|
| 71 | 72 | return $handler->handle($request); |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | 75 | // server authorization |
| 75 | - if ($request->getAttribute('ws:joinServer', null) !== null) { |
|
| 76 | - if (!$this->authorizeServer($request)) { |
|
| 76 | + if ($request->getAttribute('ws:joinServer', null) !== null) |
|
| 77 | + { |
|
| 78 | + if (!$this->authorizeServer($request)) |
|
| 79 | + { |
|
| 77 | 80 | return $this->responseFactory->createResponse(403); |
| 78 | 81 | } |
| 79 | 82 | |
@@ -81,10 +84,13 @@ discard block |
||
| 81 | 84 | } |
| 82 | 85 | |
| 83 | 86 | // topic authorization |
| 84 | - if (is_string($request->getAttribute('ws:joinTopics', null))) { |
|
| 87 | + if (is_string($request->getAttribute('ws:joinTopics', null))) |
|
| 88 | + { |
|
| 85 | 89 | $topics = explode(',', $request->getAttribute('ws:joinTopics')); |
| 86 | - foreach ($topics as $topic) { |
|
| 87 | - if (!$this->authorizeTopic($request, $topic)) { |
|
| 90 | + foreach ($topics as $topic) |
|
| 91 | + { |
|
| 92 | + if (!$this->authorizeTopic($request, $topic)) |
|
| 93 | + { |
|
| 88 | 94 | return $this->responseFactory->createResponse(403); |
| 89 | 95 | } |
| 90 | 96 | } |
@@ -104,7 +110,8 @@ discard block |
||
| 104 | 110 | private function authorizeServer(ServerRequestInterface $request): bool |
| 105 | 111 | { |
| 106 | 112 | $callback = $this->config->getServerCallback(); |
| 107 | - if ($callback === null) { |
|
| 113 | + if ($callback === null) |
|
| 114 | + { |
|
| 108 | 115 | return true; |
| 109 | 116 | } |
| 110 | 117 | |
@@ -122,7 +129,8 @@ discard block |
||
| 122 | 129 | { |
| 123 | 130 | $parameters = []; |
| 124 | 131 | $callback = $this->config->findTopicCallback($topic, $parameters); |
| 125 | - if ($callback === null) { |
|
| 132 | + if ($callback === null) |
|
| 133 | + { |
|
| 126 | 134 | return false; |
| 127 | 135 | } |
| 128 | 136 | |
@@ -141,7 +149,8 @@ discard block |
||
| 141 | 149 | { |
| 142 | 150 | /** @var \ReflectionFunctionAbstract $reflection */ |
| 143 | 151 | $reflection = null; |
| 144 | - switch (true) { |
|
| 152 | + switch (true) |
|
| 153 | + { |
|
| 145 | 154 | case $callback instanceof \Closure || is_string($callback): |
| 146 | 155 | $reflection = new \ReflectionFunction($callback); |
| 147 | 156 | break; |
@@ -159,7 +168,8 @@ discard block |
||
| 159 | 168 | [ |
| 160 | 169 | ServerRequestInterface::class => $request |
| 161 | 170 | ], |
| 162 | - function () use ($reflection, $parameters, $callback) { |
|
| 171 | + function () use ($reflection, $parameters, $callback) |
|
| 172 | + { |
|
| 163 | 173 | return call_user_func_array( |
| 164 | 174 | $callback, |
| 165 | 175 | $this->resolver->resolveArguments($reflection, $parameters) |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | parent::__construct($config); |
| 36 | 36 | |
| 37 | - foreach ($config['authorizeTopics'] as $topic => $callback) { |
|
| 37 | + foreach ($config['authorizeTopics'] as $topic => $callback){ |
|
| 38 | 38 | $this->patterns[$this->compilePattern($topic)] = $callback; |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function findTopicCallback(string $topic, array &$matches): ?callable |
| 64 | 64 | { |
| 65 | - foreach ($this->patterns as $pattern => $callback) { |
|
| 66 | - if (preg_match($pattern, $topic, $matches)) { |
|
| 65 | + foreach ($this->patterns as $pattern => $callback){ |
|
| 66 | + if (preg_match($pattern, $topic, $matches)){ |
|
| 67 | 67 | return $callback; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | private function compilePattern(string $topic): string |
| 79 | 79 | { |
| 80 | 80 | $replaces = []; |
| 81 | - if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) { |
|
| 81 | + if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)){ |
|
| 82 | 82 | $variables = array_combine($matches[1], $matches[2]); |
| 83 | - foreach ($variables as $key => $segment) { |
|
| 84 | - $replaces['{' . $key . '}'] = '(?P<' . $key . '>[^\/\.]+)'; |
|
| 83 | + foreach ($variables as $key => $segment){ |
|
| 84 | + $replaces['{'.$key.'}'] = '(?P<'.$key.'>[^\/\.]+)'; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return '/^' . strtr($topic, $replaces + ['/' => '\\/', '[' => '(?:', ']' => ')?', '.' => '\.']) . '$/iu'; |
|
| 88 | + return '/^'.strtr($topic, $replaces + ['/' => '\\/', '[' => '(?:', ']' => ')?', '.' => '\.']).'$/iu'; |
|
| 89 | 89 | } |
| 90 | 90 | } |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | parent::__construct($config); |
| 36 | 36 | |
| 37 | - foreach ($config['authorizeTopics'] as $topic => $callback) { |
|
| 37 | + foreach ($config['authorizeTopics'] as $topic => $callback) |
|
| 38 | + { |
|
| 38 | 39 | $this->patterns[$this->compilePattern($topic)] = $callback; |
| 39 | 40 | } |
| 40 | 41 | } |
@@ -62,8 +63,10 @@ discard block |
||
| 62 | 63 | */ |
| 63 | 64 | public function findTopicCallback(string $topic, array &$matches): ?callable |
| 64 | 65 | { |
| 65 | - foreach ($this->patterns as $pattern => $callback) { |
|
| 66 | - if (preg_match($pattern, $topic, $matches)) { |
|
| 66 | + foreach ($this->patterns as $pattern => $callback) |
|
| 67 | + { |
|
| 68 | + if (preg_match($pattern, $topic, $matches)) |
|
| 69 | + { |
|
| 67 | 70 | return $callback; |
| 68 | 71 | } |
| 69 | 72 | } |
@@ -78,9 +81,11 @@ discard block |
||
| 78 | 81 | private function compilePattern(string $topic): string |
| 79 | 82 | { |
| 80 | 83 | $replaces = []; |
| 81 | - if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) { |
|
| 84 | + if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) |
|
| 85 | + { |
|
| 82 | 86 | $variables = array_combine($matches[1], $matches[2]); |
| 83 | - foreach ($variables as $key => $segment) { |
|
| 87 | + foreach ($variables as $key => $segment) |
|
| 88 | + { |
|
| 84 | 89 | $replaces['{' . $key . '}'] = '(?P<' . $key . '>[^\/\.]+)'; |
| 85 | 90 | } |
| 86 | 91 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | EnvironmentInterface $env, |
| 24 | 24 | BootloadManager $bootloadManager |
| 25 | 25 | ): void { |
| 26 | - if ($env->get('CYCLE_AUTH')) { |
|
| 26 | + if ($env->get('CYCLE_AUTH')){ |
|
| 27 | 27 | $bootloadManager->bootload([CycleTokensBootloader::class]); |
| 28 | 28 | return; |
| 29 | 29 | } |
@@ -23,7 +23,8 @@ |
||
| 23 | 23 | EnvironmentInterface $env, |
| 24 | 24 | BootloadManager $bootloadManager |
| 25 | 25 | ): void { |
| 26 | - if ($env->get('CYCLE_AUTH')) { |
|
| 26 | + if ($env->get('CYCLE_AUTH')) |
|
| 27 | + { |
|
| 27 | 28 | $bootloadManager->bootload([CycleTokensBootloader::class]); |
| 28 | 29 | return; |
| 29 | 30 | } |
@@ -21,17 +21,17 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function boot(WebsocketsBootloader $ws, EnvironmentInterface $env): void |
| 23 | 23 | { |
| 24 | - if ($env->get('RR_BROADCAST_PATH') === null) { |
|
| 24 | + if ($env->get('RR_BROADCAST_PATH') === null){ |
|
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $ws->authorizeServer($env->get('WS_SERVER_CALLBACK')); |
| 29 | 29 | |
| 30 | - if ($env->get('WS_TOPIC_CALLBACK') !== null) { |
|
| 30 | + if ($env->get('WS_TOPIC_CALLBACK') !== null){ |
|
| 31 | 31 | $ws->authorizeTopic('topic', $env->get('WS_TOPIC_CALLBACK')); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ($env->get('WS_TOPIC_WILDCARD_CALLBACK') !== null) { |
|
| 34 | + if ($env->get('WS_TOPIC_WILDCARD_CALLBACK') !== null){ |
|
| 35 | 35 | $ws->authorizeTopic('wildcard.{id}', $env->get('WS_TOPIC_WILDCARD_CALLBACK')); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -21,17 +21,20 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function boot(WebsocketsBootloader $ws, EnvironmentInterface $env): void |
| 23 | 23 | { |
| 24 | - if ($env->get('RR_BROADCAST_PATH') === null) { |
|
| 24 | + if ($env->get('RR_BROADCAST_PATH') === null) |
|
| 25 | + { |
|
| 25 | 26 | return; |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | $ws->authorizeServer($env->get('WS_SERVER_CALLBACK')); |
| 29 | 30 | |
| 30 | - if ($env->get('WS_TOPIC_CALLBACK') !== null) { |
|
| 31 | + if ($env->get('WS_TOPIC_CALLBACK') !== null) |
|
| 32 | + { |
|
| 31 | 33 | $ws->authorizeTopic('topic', $env->get('WS_TOPIC_CALLBACK')); |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | - if ($env->get('WS_TOPIC_WILDCARD_CALLBACK') !== null) { |
|
| 36 | + if ($env->get('WS_TOPIC_WILDCARD_CALLBACK') !== null) |
|
| 37 | + { |
|
| 35 | 38 | $ws->authorizeTopic('wildcard.{id}', $env->get('WS_TOPIC_WILDCARD_CALLBACK')); |
| 36 | 39 | } |
| 37 | 40 | } |