@@ -94,9 +94,9 @@ |
||
94 | 94 | */ |
95 | 95 | private function getAuthContext(): AuthContextInterface |
96 | 96 | { |
97 | - try { |
|
97 | + try{ |
|
98 | 98 | return $this->container->get(AuthContextInterface::class); |
99 | - } catch (NotFoundExceptionInterface $e) { |
|
99 | + }catch (NotFoundExceptionInterface $e){ |
|
100 | 100 | throw new ScopeException('Unable to resolve auth context, invalid scope', $e->getCode(), $e); |
101 | 101 | } |
102 | 102 | } |
@@ -94,9 +94,12 @@ |
||
94 | 94 | */ |
95 | 95 | private function getAuthContext(): AuthContextInterface |
96 | 96 | { |
97 | - try { |
|
97 | + try |
|
98 | + { |
|
98 | 99 | return $this->container->get(AuthContextInterface::class); |
99 | - } catch (NotFoundExceptionInterface $e) { |
|
100 | + } |
|
101 | + catch (NotFoundExceptionInterface $e) |
|
102 | + { |
|
100 | 103 | throw new ScopeException('Unable to resolve auth context, invalid scope', $e->getCode(), $e); |
101 | 104 | } |
102 | 105 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | PermissionsInterface $permissions, |
42 | 42 | ContainerInterface $actorScope, |
43 | 43 | array $roles = [] |
44 | - ) { |
|
44 | + ){ |
|
45 | 45 | $this->roles = $roles; |
46 | 46 | $this->container = $actorScope; |
47 | 47 | $this->permissions = $permissions; |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | public function allows(string $permission, array $context = []): bool |
56 | 56 | { |
57 | 57 | $allows = false; |
58 | - foreach ($this->getRoles() as $role) { |
|
59 | - if (!$this->permissions->hasRole($role)) { |
|
58 | + foreach ($this->getRoles() as $role){ |
|
59 | + if (!$this->permissions->hasRole($role)){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getActor(): ActorInterface |
105 | 105 | { |
106 | - if (!is_null($this->actor)) { |
|
106 | + if (!is_null($this->actor)){ |
|
107 | 107 | return $this->actor; |
108 | 108 | } |
109 | 109 | |
110 | - try { |
|
110 | + try{ |
|
111 | 111 | return $this->container->get(ActorInterface::class); |
112 | - } catch (NotFoundExceptionInterface $e) { |
|
112 | + }catch (NotFoundExceptionInterface $e){ |
|
113 | 113 | throw new ScopeException('Unable to resolve Actor from the scope', $e->getCode(), $e); |
114 | 114 | } |
115 | 115 | } |
@@ -55,8 +55,10 @@ discard block |
||
55 | 55 | public function allows(string $permission, array $context = []): bool |
56 | 56 | { |
57 | 57 | $allows = false; |
58 | - foreach ($this->getRoles() as $role) { |
|
59 | - if (!$this->permissions->hasRole($role)) { |
|
58 | + foreach ($this->getRoles() as $role) |
|
59 | + { |
|
60 | + if (!$this->permissions->hasRole($role)) |
|
61 | + { |
|
60 | 62 | continue; |
61 | 63 | } |
62 | 64 | |
@@ -103,13 +105,17 @@ discard block |
||
103 | 105 | */ |
104 | 106 | public function getActor(): ActorInterface |
105 | 107 | { |
106 | - if (!is_null($this->actor)) { |
|
108 | + if (!is_null($this->actor)) |
|
109 | + { |
|
107 | 110 | return $this->actor; |
108 | 111 | } |
109 | 112 | |
110 | - try { |
|
113 | + try |
|
114 | + { |
|
111 | 115 | return $this->container->get(ActorInterface::class); |
112 | - } catch (NotFoundExceptionInterface $e) { |
|
116 | + } |
|
117 | + catch (NotFoundExceptionInterface $e) |
|
118 | + { |
|
113 | 119 | throw new ScopeException('Unable to resolve Actor from the scope', $e->getCode(), $e); |
114 | 120 | } |
115 | 121 | } |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function getActor(TokenInterface $token): ?object |
53 | 53 | { |
54 | - foreach ($this->getProviders() as $provider) { |
|
55 | - if (!$provider instanceof ActorProviderInterface) { |
|
54 | + foreach ($this->getProviders() as $provider){ |
|
55 | + if (!$provider instanceof ActorProviderInterface){ |
|
56 | 56 | throw new AuthException(sprintf( |
57 | 57 | 'Expected `ActorProviderInterface`, got `%s`', |
58 | 58 | get_class($provider) |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | $actor = $provider->getActor($token); |
63 | - if ($actor !== null) { |
|
63 | + if ($actor !== null){ |
|
64 | 64 | return $actor; |
65 | 65 | } |
66 | 66 | } |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | */ |
84 | 84 | private function getProviders(): \Generator |
85 | 85 | { |
86 | - foreach ($this->actorProvider as $provider) { |
|
87 | - if ($provider instanceof Autowire) { |
|
86 | + foreach ($this->actorProvider as $provider){ |
|
87 | + if ($provider instanceof Autowire){ |
|
88 | 88 | yield $provider->resolve($this->factory); |
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if (is_object($provider)) { |
|
92 | + if (is_object($provider)){ |
|
93 | 93 | yield $provider; |
94 | 94 | continue; |
95 | 95 | } |
@@ -51,8 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function getActor(TokenInterface $token): ?object |
53 | 53 | { |
54 | - foreach ($this->getProviders() as $provider) { |
|
55 | - if (!$provider instanceof ActorProviderInterface) { |
|
54 | + foreach ($this->getProviders() as $provider) |
|
55 | + { |
|
56 | + if (!$provider instanceof ActorProviderInterface) |
|
57 | + { |
|
56 | 58 | throw new AuthException(sprintf( |
57 | 59 | 'Expected `ActorProviderInterface`, got `%s`', |
58 | 60 | get_class($provider) |
@@ -60,7 +62,8 @@ discard block |
||
60 | 62 | } |
61 | 63 | |
62 | 64 | $actor = $provider->getActor($token); |
63 | - if ($actor !== null) { |
|
65 | + if ($actor !== null) |
|
66 | + { |
|
64 | 67 | return $actor; |
65 | 68 | } |
66 | 69 | } |
@@ -83,13 +86,16 @@ discard block |
||
83 | 86 | */ |
84 | 87 | private function getProviders(): \Generator |
85 | 88 | { |
86 | - foreach ($this->actorProvider as $provider) { |
|
87 | - if ($provider instanceof Autowire) { |
|
89 | + foreach ($this->actorProvider as $provider) |
|
90 | + { |
|
91 | + if ($provider instanceof Autowire) |
|
92 | + { |
|
88 | 93 | yield $provider->resolve($this->factory); |
89 | 94 | continue; |
90 | 95 | } |
91 | 96 | |
92 | - if (is_object($provider)) { |
|
97 | + if (is_object($provider)) |
|
98 | + { |
|
93 | 99 | yield $provider; |
94 | 100 | continue; |
95 | 101 | } |
@@ -87,8 +87,8 @@ |
||
87 | 87 | $registry = new TransportRegistry(); |
88 | 88 | $registry->setDefaultTransport($config->getDefaultTransport()); |
89 | 89 | |
90 | - foreach ($config->getTransports() as $name => $transport) { |
|
91 | - if ($transport instanceof Autowire) { |
|
90 | + foreach ($config->getTransports() as $name => $transport){ |
|
91 | + if ($transport instanceof Autowire){ |
|
92 | 92 | $transport = $transport->resolve($factory); |
93 | 93 | } |
94 | 94 |
@@ -87,8 +87,10 @@ |
||
87 | 87 | $registry = new TransportRegistry(); |
88 | 88 | $registry->setDefaultTransport($config->getDefaultTransport()); |
89 | 89 | |
90 | - foreach ($config->getTransports() as $name => $transport) { |
|
91 | - if ($transport instanceof Autowire) { |
|
90 | + foreach ($config->getTransports() as $name => $transport) |
|
91 | + { |
|
92 | + if ($transport instanceof Autowire) |
|
93 | + { |
|
92 | 94 | $transport = $transport->resolve($factory); |
93 | 95 | } |
94 | 96 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | private function actor(AuthContextInterface $context): ActorInterface |
39 | 39 | { |
40 | 40 | $actor = $context->getActor(); |
41 | - if ($actor instanceof ActorInterface) { |
|
41 | + if ($actor instanceof ActorInterface){ |
|
42 | 42 | return $actor; |
43 | 43 | } |
44 | 44 |
@@ -38,7 +38,8 @@ |
||
38 | 38 | private function actor(AuthContextInterface $context): ActorInterface |
39 | 39 | { |
40 | 40 | $actor = $context->getActor(); |
41 | - if ($actor instanceof ActorInterface) { |
|
41 | + if ($actor instanceof ActorInterface) |
|
42 | + { |
|
42 | 43 | return $actor; |
43 | 44 | } |
44 | 45 |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | public function getTransports(): array |
42 | 42 | { |
43 | 43 | $transports = []; |
44 | - foreach ($this->config['transports'] as $name => $transport) { |
|
45 | - if (is_object($transport) && !$transport instanceof Autowire) { |
|
44 | + foreach ($this->config['transports'] as $name => $transport){ |
|
45 | + if (is_object($transport) && !$transport instanceof Autowire){ |
|
46 | 46 | $transports[$name] = $transport; |
47 | 47 | continue; |
48 | 48 | } |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private function wire($item): Autowire |
63 | 63 | { |
64 | - if ($item instanceof Autowire) { |
|
64 | + if ($item instanceof Autowire){ |
|
65 | 65 | return $item; |
66 | 66 | } |
67 | 67 | |
68 | - if (is_string($item)) { |
|
68 | + if (is_string($item)){ |
|
69 | 69 | return new Autowire($item); |
70 | 70 | } |
71 | 71 | |
72 | - if (is_array($item) && isset($item['class'])) { |
|
72 | + if (is_array($item) && isset($item['class'])){ |
|
73 | 73 | return new Autowire($item['class'], $item['options'] ?? []); |
74 | 74 | } |
75 | 75 |
@@ -41,8 +41,10 @@ discard block |
||
41 | 41 | public function getTransports(): array |
42 | 42 | { |
43 | 43 | $transports = []; |
44 | - foreach ($this->config['transports'] as $name => $transport) { |
|
45 | - if (is_object($transport) && !$transport instanceof Autowire) { |
|
44 | + foreach ($this->config['transports'] as $name => $transport) |
|
45 | + { |
|
46 | + if (is_object($transport) && !$transport instanceof Autowire) |
|
47 | + { |
|
46 | 48 | $transports[$name] = $transport; |
47 | 49 | continue; |
48 | 50 | } |
@@ -61,15 +63,18 @@ discard block |
||
61 | 63 | */ |
62 | 64 | private function wire($item): Autowire |
63 | 65 | { |
64 | - if ($item instanceof Autowire) { |
|
66 | + if ($item instanceof Autowire) |
|
67 | + { |
|
65 | 68 | return $item; |
66 | 69 | } |
67 | 70 | |
68 | - if (is_string($item)) { |
|
71 | + if (is_string($item)) |
|
72 | + { |
|
69 | 73 | return new Autowire($item); |
70 | 74 | } |
71 | 75 | |
72 | - if (is_array($item) && isset($item['class'])) { |
|
76 | + if (is_array($item) && isset($item['class'])) |
|
77 | + { |
|
73 | 78 | return new Autowire($item['class'], $item['options'] ?? []); |
74 | 79 | } |
75 | 80 |
@@ -38,25 +38,25 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function load(string $id): ?TokenInterface |
40 | 40 | { |
41 | - if (strpos($id, ':') === false) { |
|
41 | + if (strpos($id, ':') === false){ |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | |
45 | 45 | list($pk, $hash) = explode(':', $id, 2); |
46 | 46 | |
47 | - if (!is_numeric($pk)) { |
|
47 | + if (!is_numeric($pk)){ |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 | |
51 | 51 | /** @var TokenInterface $token */ |
52 | 52 | $token = $this->orm->getRepository(Token::class)->findByPK((int)$pk); |
53 | 53 | |
54 | - if ($token === null || $token->getID() !== $id) { |
|
54 | + if ($token === null || $token->getID() !== $id){ |
|
55 | 55 | // hijacked or deleted |
56 | 56 | return null; |
57 | 57 | } |
58 | 58 | |
59 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
59 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()){ |
|
60 | 60 | $this->delete($token); |
61 | 61 | return null; |
62 | 62 | } |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
71 | 71 | { |
72 | - try { |
|
72 | + try{ |
|
73 | 73 | $token = new Token($this->randomHash(128), $payload, new \DateTimeImmutable(), $expiresAt); |
74 | 74 | |
75 | 75 | (new Transaction($this->orm))->persist($token)->run(); |
76 | 76 | |
77 | 77 | return $token; |
78 | - } catch (\Throwable $e) { |
|
78 | + }catch (\Throwable $e){ |
|
79 | 79 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
80 | 80 | } |
81 | 81 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function delete(TokenInterface $token): void |
87 | 87 | { |
88 | - try { |
|
88 | + try{ |
|
89 | 89 | (new Transaction($this->orm))->delete($token)->run(); |
90 | - } catch (\Throwable $e) { |
|
90 | + }catch (\Throwable $e){ |
|
91 | 91 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
92 | 92 | } |
93 | 93 | } |
@@ -38,25 +38,29 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function load(string $id): ?TokenInterface |
40 | 40 | { |
41 | - if (strpos($id, ':') === false) { |
|
41 | + if (strpos($id, ':') === false) |
|
42 | + { |
|
42 | 43 | return null; |
43 | 44 | } |
44 | 45 | |
45 | 46 | list($pk, $hash) = explode(':', $id, 2); |
46 | 47 | |
47 | - if (!is_numeric($pk)) { |
|
48 | + if (!is_numeric($pk)) |
|
49 | + { |
|
48 | 50 | return null; |
49 | 51 | } |
50 | 52 | |
51 | 53 | /** @var TokenInterface $token */ |
52 | 54 | $token = $this->orm->getRepository(Token::class)->findByPK((int)$pk); |
53 | 55 | |
54 | - if ($token === null || $token->getID() !== $id) { |
|
56 | + if ($token === null || $token->getID() !== $id) |
|
57 | + { |
|
55 | 58 | // hijacked or deleted |
56 | 59 | return null; |
57 | 60 | } |
58 | 61 | |
59 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
62 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) |
|
63 | + { |
|
60 | 64 | $this->delete($token); |
61 | 65 | return null; |
62 | 66 | } |
@@ -69,13 +73,16 @@ discard block |
||
69 | 73 | */ |
70 | 74 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
71 | 75 | { |
72 | - try { |
|
76 | + try |
|
77 | + { |
|
73 | 78 | $token = new Token($this->randomHash(128), $payload, new \DateTimeImmutable(), $expiresAt); |
74 | 79 | |
75 | 80 | (new Transaction($this->orm))->persist($token)->run(); |
76 | 81 | |
77 | 82 | return $token; |
78 | - } catch (\Throwable $e) { |
|
83 | + } |
|
84 | + catch (\Throwable $e) |
|
85 | + { |
|
79 | 86 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
80 | 87 | } |
81 | 88 | } |
@@ -85,9 +92,12 @@ discard block |
||
85 | 92 | */ |
86 | 93 | public function delete(TokenInterface $token): void |
87 | 94 | { |
88 | - try { |
|
95 | + try |
|
96 | + { |
|
89 | 97 | (new Transaction($this->orm))->delete($token)->run(); |
90 | - } catch (\Throwable $e) { |
|
98 | + } |
|
99 | + catch (\Throwable $e) |
|
100 | + { |
|
91 | 101 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
92 | 102 | } |
93 | 103 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | public static function unpack(array $data): Token |
101 | 101 | { |
102 | 102 | $expiresAt = null; |
103 | - if ($data['expiresAt'] != null) { |
|
103 | + if ($data['expiresAt'] != null){ |
|
104 | 104 | $expiresAt = (new \DateTimeImmutable())->setTimestamp($data['expiresAt']); |
105 | 105 | } |
106 | 106 |
@@ -100,7 +100,8 @@ |
||
100 | 100 | public static function unpack(array $data): Token |
101 | 101 | { |
102 | 102 | $expiresAt = null; |
103 | - if ($data['expiresAt'] != null) { |
|
103 | + if ($data['expiresAt'] != null) |
|
104 | + { |
|
104 | 105 | $expiresAt = (new \DateTimeImmutable())->setTimestamp($data['expiresAt']); |
105 | 106 | } |
106 | 107 |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function load(string $id): ?TokenInterface |
42 | 42 | { |
43 | - try { |
|
43 | + try{ |
|
44 | 44 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
45 | 45 | $token = Token::unpack($tokenData); |
46 | - } catch (\Throwable $e) { |
|
46 | + }catch (\Throwable $e){ |
|
47 | 47 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
48 | 48 | } |
49 | 49 | |
50 | - if ($token->getID() !== $id) { |
|
50 | + if ($token->getID() !== $id){ |
|
51 | 51 | return null; |
52 | 52 | } |
53 | 53 | |
54 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() > new \DateTime()) { |
|
54 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() > new \DateTime()){ |
|
55 | 55 | $this->delete($token); |
56 | 56 | return null; |
57 | 57 | } |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
66 | 66 | { |
67 | - try { |
|
67 | + try{ |
|
68 | 68 | $token = new Token($this->randomHash(123), $payload, $expiresAt); |
69 | 69 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
70 | 70 | |
71 | 71 | return $token; |
72 | - } catch (\Throwable $e) { |
|
72 | + }catch (\Throwable $e){ |
|
73 | 73 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
74 | 74 | } |
75 | 75 | } |
@@ -40,18 +40,23 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function load(string $id): ?TokenInterface |
42 | 42 | { |
43 | - try { |
|
43 | + try |
|
44 | + { |
|
44 | 45 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
45 | 46 | $token = Token::unpack($tokenData); |
46 | - } catch (\Throwable $e) { |
|
47 | + } |
|
48 | + catch (\Throwable $e) |
|
49 | + { |
|
47 | 50 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
48 | 51 | } |
49 | 52 | |
50 | - if ($token->getID() !== $id) { |
|
53 | + if ($token->getID() !== $id) |
|
54 | + { |
|
51 | 55 | return null; |
52 | 56 | } |
53 | 57 | |
54 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() > new \DateTime()) { |
|
58 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() > new \DateTime()) |
|
59 | + { |
|
55 | 60 | $this->delete($token); |
56 | 61 | return null; |
57 | 62 | } |
@@ -64,12 +69,15 @@ discard block |
||
64 | 69 | */ |
65 | 70 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
66 | 71 | { |
67 | - try { |
|
72 | + try |
|
73 | + { |
|
68 | 74 | $token = new Token($this->randomHash(123), $payload, $expiresAt); |
69 | 75 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
70 | 76 | |
71 | 77 | return $token; |
72 | - } catch (\Throwable $e) { |
|
78 | + } |
|
79 | + catch (\Throwable $e) |
|
80 | + { |
|
73 | 81 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
74 | 82 | } |
75 | 83 | } |