Skip to content

Commit c89462e

Browse files
committed
Add support to deferred context server for setting token store easily
1 parent dfc2971 commit c89462e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/Deferral/DeferredContextCliServer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use SlackPhp\Framework\{AppServer, Context, Exception};
9+
use SlackPhp\Framework\Auth\TokenStore;
910
use Throwable;
1011

1112
/**
@@ -17,6 +18,7 @@ class DeferredContextCliServer extends AppServer
1718
private array $args;
1819
private ?Closure $deserializeCallback;
1920
private int $exitCode = 0;
21+
private TokenStore $tokenStore;
2022

2123
/**
2224
* @param string[] $args
@@ -40,6 +42,17 @@ public function withDeserializeCallback(callable $deserializeCallback): self
4042
return $this;
4143
}
4244

45+
/**
46+
* @param TokenStore $tokenStore
47+
* @return $this
48+
*/
49+
public function withTokenStore(TokenStore $tokenStore): self
50+
{
51+
$this->tokenStore = $tokenStore;
52+
53+
return $this;
54+
}
55+
4356
protected function init(): void
4457
{
4558
global $argv;
@@ -51,6 +64,9 @@ public function start(): void
5164
try {
5265
$this->getLogger()->debug('Started processing of deferred context');
5366
$context = $this->deserializeContext($this->args[1] ?? '');
67+
if (isset($this->tokenStore)) {
68+
$context->withTokenStore($this->tokenStore);
69+
}
5470
$this->getApp()->handle($context);
5571
$this->getLogger()->debug('Completed processing of deferred context');
5672
} catch (Throwable $exception) {

0 commit comments

Comments
 (0)