@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | string $mergeMode = self::FOLLOW, |
| 46 | 46 | int $mode = FilesInterface::READONLY |
| 47 | 47 | ): void { |
| 48 | - if (!$this->files->isFile($filename)) { |
|
| 48 | + if (!$this->files->isFile($filename)){ |
|
| 49 | 49 | throw new PublishException("Given '{$filename}' is not valid file"); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if ($this->files->exists($destination)) { |
|
| 53 | - if ($this->files->md5($destination) == $this->files->md5($filename)) { |
|
| 52 | + if ($this->files->exists($destination)){ |
|
| 53 | + if ($this->files->md5($destination) == $this->files->md5($filename)){ |
|
| 54 | 54 | //Nothing to do |
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if ($mergeMode == self::FOLLOW) { |
|
| 58 | + if ($mergeMode == self::FOLLOW){ |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | string $mergeMode = self::REPLACE, |
| 78 | 78 | int $mode = FilesInterface::READONLY |
| 79 | 79 | ): void { |
| 80 | - if (!$this->files->isDirectory($directory)) { |
|
| 80 | + if (!$this->files->isDirectory($directory)){ |
|
| 81 | 81 | throw new PublishException("Given '{$directory}' is not valid directory"); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * @var SplFileInfo $file |
| 89 | 89 | */ |
| 90 | - foreach ($finder->getIterator() as $file) { |
|
| 90 | + foreach ($finder->getIterator() as $file){ |
|
| 91 | 91 | $this->publish( |
| 92 | 92 | (string)$file, |
| 93 | - $destination . '/' . $file->getRelativePathname(), |
|
| 93 | + $destination.'/'.$file->getRelativePathname(), |
|
| 94 | 94 | $mergeMode, |
| 95 | 95 | $mode |
| 96 | 96 | ); |
@@ -45,17 +45,21 @@ discard block |
||
| 45 | 45 | string $mergeMode = self::FOLLOW, |
| 46 | 46 | int $mode = FilesInterface::READONLY |
| 47 | 47 | ): void { |
| 48 | - if (!$this->files->isFile($filename)) { |
|
| 48 | + if (!$this->files->isFile($filename)) |
|
| 49 | + { |
|
| 49 | 50 | throw new PublishException("Given '{$filename}' is not valid file"); |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | - if ($this->files->exists($destination)) { |
|
| 53 | - if ($this->files->md5($destination) == $this->files->md5($filename)) { |
|
| 53 | + if ($this->files->exists($destination)) |
|
| 54 | + { |
|
| 55 | + if ($this->files->md5($destination) == $this->files->md5($filename)) |
|
| 56 | + { |
|
| 54 | 57 | //Nothing to do |
| 55 | 58 | return; |
| 56 | 59 | } |
| 57 | 60 | |
| 58 | - if ($mergeMode == self::FOLLOW) { |
|
| 61 | + if ($mergeMode == self::FOLLOW) |
|
| 62 | + { |
|
| 59 | 63 | return; |
| 60 | 64 | } |
| 61 | 65 | } |
@@ -77,7 +81,8 @@ discard block |
||
| 77 | 81 | string $mergeMode = self::REPLACE, |
| 78 | 82 | int $mode = FilesInterface::READONLY |
| 79 | 83 | ): void { |
| 80 | - if (!$this->files->isDirectory($directory)) { |
|
| 84 | + if (!$this->files->isDirectory($directory)) |
|
| 85 | + { |
|
| 81 | 86 | throw new PublishException("Given '{$directory}' is not valid directory"); |
| 82 | 87 | } |
| 83 | 88 | |
@@ -87,7 +92,8 @@ discard block |
||
| 87 | 92 | /** |
| 88 | 93 | * @var SplFileInfo $file |
| 89 | 94 | */ |
| 90 | - foreach ($finder->getIterator() as $file) { |
|
| 95 | + foreach ($finder->getIterator() as $file) |
|
| 96 | + { |
|
| 91 | 97 | $this->publish( |
| 92 | 98 | (string)$file, |
| 93 | 99 | $destination . '/' . $file->getRelativePathname(), |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | public function exists($value, string $role, ?string $field = null): bool |
| 39 | 39 | { |
| 40 | 40 | $repository = $this->orm->getRepository($role); |
| 41 | - if ($field === null) { |
|
| 41 | + if ($field === null){ |
|
| 42 | 42 | return $repository->findByPK($value) !== null; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $values = $this->withValues($withFields); |
| 58 | 58 | $values[$field] = $value; |
| 59 | 59 | |
| 60 | - if ($this->isProvidedByContext($role, $values)) { |
|
| 60 | + if ($this->isProvidedByContext($role, $values)){ |
|
| 61 | 61 | return true; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | private function withValues(array $fields): array |
| 72 | 72 | { |
| 73 | 73 | $values = []; |
| 74 | - foreach ($fields as $field) { |
|
| 75 | - if ($this->getValidator()->hasValue($field)) { |
|
| 74 | + foreach ($fields as $field){ |
|
| 75 | + if ($this->getValidator()->hasValue($field)){ |
|
| 76 | 76 | $values[$field] = $this->getValidator()->getValue($field); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | private function isProvidedByContext(string $role, array $values): bool |
| 89 | 89 | { |
| 90 | 90 | $entity = $this->getValidator()->getContext(); |
| 91 | - if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) { |
|
| 91 | + if (!is_object($entity) || !$this->orm->getHeap()->has($entity)){ |
|
| 92 | 92 | return false; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $extract = $this->orm->getMapper($role)->extract($entity); |
| 96 | - foreach ($values as $field => $value) { |
|
| 97 | - if (!isset($extract[$field]) || $extract[$field] !== $value) { |
|
| 96 | + foreach ($values as $field => $value){ |
|
| 97 | + if (!isset($extract[$field]) || $extract[$field] !== $value){ |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | public function exists($value, string $role, ?string $field = null): bool |
| 39 | 39 | { |
| 40 | 40 | $repository = $this->orm->getRepository($role); |
| 41 | - if ($field === null) { |
|
| 41 | + if ($field === null) |
|
| 42 | + { |
|
| 42 | 43 | return $repository->findByPK($value) !== null; |
| 43 | 44 | } |
| 44 | 45 | |
@@ -57,7 +58,8 @@ discard block |
||
| 57 | 58 | $values = $this->withValues($withFields); |
| 58 | 59 | $values[$field] = $value; |
| 59 | 60 | |
| 60 | - if ($this->isProvidedByContext($role, $values)) { |
|
| 61 | + if ($this->isProvidedByContext($role, $values)) |
|
| 62 | + { |
|
| 61 | 63 | return true; |
| 62 | 64 | } |
| 63 | 65 | |
@@ -71,8 +73,10 @@ discard block |
||
| 71 | 73 | private function withValues(array $fields): array |
| 72 | 74 | { |
| 73 | 75 | $values = []; |
| 74 | - foreach ($fields as $field) { |
|
| 75 | - if ($this->getValidator()->hasValue($field)) { |
|
| 76 | + foreach ($fields as $field) |
|
| 77 | + { |
|
| 78 | + if ($this->getValidator()->hasValue($field)) |
|
| 79 | + { |
|
| 76 | 80 | $values[$field] = $this->getValidator()->getValue($field); |
| 77 | 81 | } |
| 78 | 82 | } |
@@ -88,13 +92,16 @@ discard block |
||
| 88 | 92 | private function isProvidedByContext(string $role, array $values): bool |
| 89 | 93 | { |
| 90 | 94 | $entity = $this->getValidator()->getContext(); |
| 91 | - if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) { |
|
| 95 | + if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) |
|
| 96 | + { |
|
| 92 | 97 | return false; |
| 93 | 98 | } |
| 94 | 99 | |
| 95 | 100 | $extract = $this->orm->getMapper($role)->extract($entity); |
| 96 | - foreach ($values as $field => $value) { |
|
| 97 | - if (!isset($extract[$field]) || $extract[$field] !== $value) { |
|
| 101 | + foreach ($values as $field => $value) |
|
| 102 | + { |
|
| 103 | + if (!isset($extract[$field]) || $extract[$field] !== $value) |
|
| 104 | + { |
|
| 98 | 105 | return false; |
| 99 | 106 | } |
| 100 | 107 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | HandlerInterface $handler, |
| 54 | 54 | FilesInterface $files, |
| 55 | 55 | LoggerInterface $logger = null |
| 56 | - ) { |
|
| 56 | + ){ |
|
| 57 | 57 | $this->directory = $directory; |
| 58 | 58 | $this->maxFiles = $maxFiles; |
| 59 | 59 | $this->verbosity = $verbosity; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
| 71 | 71 | |
| 72 | - if ($this->logger !== null) { |
|
| 72 | + if ($this->logger !== null){ |
|
| 73 | 73 | $this->logger->error($snapshot->getMessage()); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -102,18 +102,18 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $finder = new Finder(); |
| 104 | 104 | $finder->in($this->directory)->sort( |
| 105 | - static function (SplFileInfo $a, SplFileInfo $b) { |
|
| 105 | + static function (SplFileInfo $a, SplFileInfo $b){ |
|
| 106 | 106 | return $b->getMTime() - $a->getMTime(); |
| 107 | 107 | } |
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | 110 | $count = 0; |
| 111 | - foreach ($finder as $file) { |
|
| 111 | + foreach ($finder as $file){ |
|
| 112 | 112 | $count++; |
| 113 | - if ($count > $this->maxFiles) { |
|
| 114 | - try { |
|
| 113 | + if ($count > $this->maxFiles){ |
|
| 114 | + try{ |
|
| 115 | 115 | $this->files->delete($file->getRealPath()); |
| 116 | - } catch (FilesException $e) { |
|
| 116 | + }catch (FilesException $e){ |
|
| 117 | 117 | // ignore |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -69,7 +69,8 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
| 71 | 71 | |
| 72 | - if ($this->logger !== null) { |
|
| 72 | + if ($this->logger !== null) |
|
| 73 | + { |
|
| 73 | 74 | $this->logger->error($snapshot->getMessage()); |
| 74 | 75 | } |
| 75 | 76 | |
@@ -102,18 +103,24 @@ discard block |
||
| 102 | 103 | { |
| 103 | 104 | $finder = new Finder(); |
| 104 | 105 | $finder->in($this->directory)->sort( |
| 105 | - static function (SplFileInfo $a, SplFileInfo $b) { |
|
| 106 | + static function (SplFileInfo $a, SplFileInfo $b) |
|
| 107 | + { |
|
| 106 | 108 | return $b->getMTime() - $a->getMTime(); |
| 107 | 109 | } |
| 108 | 110 | ); |
| 109 | 111 | |
| 110 | 112 | $count = 0; |
| 111 | - foreach ($finder as $file) { |
|
| 113 | + foreach ($finder as $file) |
|
| 114 | + { |
|
| 112 | 115 | $count++; |
| 113 | - if ($count > $this->maxFiles) { |
|
| 114 | - try { |
|
| 116 | + if ($count > $this->maxFiles) |
|
| 117 | + { |
|
| 118 | + try |
|
| 119 | + { |
|
| 115 | 120 | $this->files->delete($file->getRealPath()); |
| 116 | - } catch (FilesException $e) { |
|
| 121 | + } |
|
| 122 | + catch (FilesException $e) |
|
| 123 | + { |
|
| 117 | 124 | // ignore |
| 118 | 125 | } |
| 119 | 126 | } |
@@ -43,8 +43,8 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $state->setTag('php', phpversion()); |
| 45 | 45 | |
| 46 | - if ($this->container->get(DispatcherInterface::class)) { |
|
| 47 | - switch (get_class($this->container->get(DispatcherInterface::class))) { |
|
| 46 | + if ($this->container->get(DispatcherInterface::class)){ |
|
| 47 | + switch (get_class($this->container->get(DispatcherInterface::class))){ |
|
| 48 | 48 | case RrDispatcher::class: |
| 49 | 49 | $state->setTag('dispatcher', 'roadrunner'); |
| 50 | 50 | break; |
@@ -43,8 +43,10 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $state->setTag('php', phpversion()); |
| 45 | 45 | |
| 46 | - if ($this->container->get(DispatcherInterface::class)) { |
|
| 47 | - switch (get_class($this->container->get(DispatcherInterface::class))) { |
|
| 46 | + if ($this->container->get(DispatcherInterface::class)) |
|
| 47 | + { |
|
| 48 | + switch (get_class($this->container->get(DispatcherInterface::class))) |
|
| 49 | + { |
|
| 48 | 50 | case RrDispatcher::class: |
| 49 | 51 | $state->setTag('dispatcher', 'roadrunner'); |
| 50 | 52 | break; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function populate(StateInterface $state): void |
| 41 | 41 | { |
| 42 | - if ($this->request === null) { |
|
| 42 | + if ($this->request === null){ |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $state->setVariable('headers', $this->request->getHeaders()); |
| 50 | 50 | |
| 51 | - if ($this->request->getQueryParams() !== []) { |
|
| 51 | + if ($this->request->getQueryParams() !== []){ |
|
| 52 | 52 | $state->setVariable('query', $this->request->getQueryParams()); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ($this->request->getParsedBody() !== null) { |
|
| 55 | + if ($this->request->getParsedBody() !== null){ |
|
| 56 | 56 | $state->setVariable('data', $this->request->getParsedBody()); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function populate(StateInterface $state): void |
| 41 | 41 | { |
| 42 | - if ($this->request === null) { |
|
| 42 | + if ($this->request === null) |
|
| 43 | + { |
|
| 43 | 44 | return; |
| 44 | 45 | } |
| 45 | 46 | |
@@ -48,11 +49,13 @@ discard block |
||
| 48 | 49 | |
| 49 | 50 | $state->setVariable('headers', $this->request->getHeaders()); |
| 50 | 51 | |
| 51 | - if ($this->request->getQueryParams() !== []) { |
|
| 52 | + if ($this->request->getQueryParams() !== []) |
|
| 53 | + { |
|
| 52 | 54 | $state->setVariable('query', $this->request->getQueryParams()); |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | - if ($this->request->getParsedBody() !== null) { |
|
| 57 | + if ($this->request->getParsedBody() !== null) |
|
| 58 | + { |
|
| 56 | 59 | $state->setVariable('data', $this->request->getParsedBody()); |
| 57 | 60 | } |
| 58 | 61 | } |
@@ -43,29 +43,29 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | protected function mapDirectories(array $directories): array |
| 45 | 45 | { |
| 46 | - if (!isset($directories['root'])) { |
|
| 46 | + if (!isset($directories['root'])){ |
|
| 47 | 47 | throw new BootException('Missing required directory `root`'); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if (!isset($directories['app'])) { |
|
| 51 | - $directories['app'] = $directories['root'] . '/app/'; |
|
| 50 | + if (!isset($directories['app'])){ |
|
| 51 | + $directories['app'] = $directories['root'].'/app/'; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return array_merge( |
| 55 | 55 | [ |
| 56 | 56 | // public root |
| 57 | - 'public' => $directories['root'] . '/public/', |
|
| 57 | + 'public' => $directories['root'].'/public/', |
|
| 58 | 58 | |
| 59 | 59 | // vendor libraries |
| 60 | - 'vendor' => $directories['root'] . '/vendor/', |
|
| 60 | + 'vendor' => $directories['root'].'/vendor/', |
|
| 61 | 61 | |
| 62 | 62 | // data directories |
| 63 | - 'runtime' => $directories['root'] . '/runtime/', |
|
| 64 | - 'cache' => $directories['root'] . '/runtime/cache/', |
|
| 63 | + 'runtime' => $directories['root'].'/runtime/', |
|
| 64 | + 'cache' => $directories['root'].'/runtime/cache/', |
|
| 65 | 65 | |
| 66 | 66 | // application directories |
| 67 | - 'config' => $directories['app'] . '/config/', |
|
| 68 | - 'resources' => $directories['app'] . '/resources/', |
|
| 67 | + 'config' => $directories['app'].'/config/', |
|
| 68 | + 'resources' => $directories['app'].'/resources/', |
|
| 69 | 69 | ], |
| 70 | 70 | $directories |
| 71 | 71 | ); |
@@ -43,11 +43,13 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | protected function mapDirectories(array $directories): array |
| 45 | 45 | { |
| 46 | - if (!isset($directories['root'])) { |
|
| 46 | + if (!isset($directories['root'])) |
|
| 47 | + { |
|
| 47 | 48 | throw new BootException('Missing required directory `root`'); |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - if (!isset($directories['app'])) { |
|
| 51 | + if (!isset($directories['app'])) |
|
| 52 | + { |
|
| 51 | 53 | $directories['app'] = $directories['root'] . '/app/'; |
| 52 | 54 | } |
| 53 | 55 | |
@@ -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 | } |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | private function getRequest(): ServerRequestInterface |
| 176 | 176 | { |
| 177 | - try { |
|
| 177 | + try{ |
|
| 178 | 178 | return $this->container->get(ServerRequestInterface::class); |
| 179 | - } catch (NotFoundExceptionInterface $e) { |
|
| 179 | + }catch (NotFoundExceptionInterface $e){ |
|
| 180 | 180 | throw new ScopeException('Unable to receive active request', $e->getCode(), $e); |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | private function getCookieQueue(): CookieQueue |
| 190 | 190 | { |
| 191 | - try { |
|
| 191 | + try{ |
|
| 192 | 192 | return $this->container->get(CookieQueue::class); |
| 193 | - } catch (NotFoundExceptionInterface $e) { |
|
| 193 | + }catch (NotFoundExceptionInterface $e){ |
|
| 194 | 194 | throw new ScopeException('Unable to receive cookie queue, invalid request scope', $e->getCode(), $e); |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -169,9 +169,12 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | private function getRequest(): ServerRequestInterface |
| 171 | 171 | { |
| 172 | - try { |
|
| 172 | + try |
|
| 173 | + { |
|
| 173 | 174 | return $this->container->get(ServerRequestInterface::class); |
| 174 | - } catch (NotFoundExceptionInterface $e) { |
|
| 175 | + } |
|
| 176 | + catch (NotFoundExceptionInterface $e) |
|
| 177 | + { |
|
| 175 | 178 | throw new ScopeException('Unable to receive active request', $e->getCode(), $e); |
| 176 | 179 | } |
| 177 | 180 | } |
@@ -183,9 +186,12 @@ discard block |
||
| 183 | 186 | */ |
| 184 | 187 | private function getCookieQueue(): CookieQueue |
| 185 | 188 | { |
| 186 | - try { |
|
| 189 | + try |
|
| 190 | + { |
|
| 187 | 191 | return $this->container->get(CookieQueue::class); |
| 188 | - } catch (NotFoundExceptionInterface $e) { |
|
| 192 | + } |
|
| 193 | + catch (NotFoundExceptionInterface $e) |
|
| 194 | + { |
|
| 189 | 195 | throw new ScopeException('Unable to receive cookie queue, invalid request scope', $e->getCode(), $e); |
| 190 | 196 | } |
| 191 | 197 | } |