66
77use Closure ;
88use SlackPhp \Framework \{AppServer , Context , Exception };
9- use SlackPhp \Framework \Auth \TokenStore ;
109use Throwable ;
1110
1211/**
@@ -18,7 +17,6 @@ class DeferredContextCliServer extends AppServer
1817 private array $ args ;
1918 private ?Closure $ deserializeCallback ;
2019 private int $ exitCode = 0 ;
21- private TokenStore $ tokenStore ;
2220
2321 /**
2422 * @param string[] $args
@@ -42,17 +40,6 @@ public function withDeserializeCallback(callable $deserializeCallback): self
4240 return $ this ;
4341 }
4442
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-
5643 protected function init (): void
5744 {
5845 global $ argv ;
@@ -61,28 +48,32 @@ protected function init(): void
6148
6249 public function start (): void
6350 {
51+ // Process args.
52+ $ serializedContext = $ this ->args [1 ] ?? '' ;
53+ $ softExit = ($ this ->args [2 ] ?? '' ) === '--soft-exit ' ;
54+
55+ // Run the app.
6456 try {
6557 $ this ->getLogger ()->debug ('Started processing of deferred context ' );
66- $ context = $ this ->deserializeContext ($ this ->args [1 ] ?? '' );
67- if (isset ($ this ->tokenStore )) {
68- $ context ->withTokenStore ($ this ->tokenStore );
69- }
58+ $ context = $ this ->deserializeContext ($ serializedContext );
59+ $ this ->getAppCredentials ();
7060 $ this ->getApp ()->handle ($ context );
7161 $ this ->getLogger ()->debug ('Completed processing of deferred context ' );
7262 } catch (Throwable $ exception ) {
7363 $ this ->getLogger ()->error ('Error occurred during processing of deferred context ' , compact ('exception ' ));
7464 $ this ->exitCode = 1 ;
7565 }
7666
77- $ this ->stop ();
67+ if (!$ softExit ) {
68+ $ this ->stop ();
69+ }
7870 }
7971
72+ /**
73+ * @return never-returns
74+ */
8075 public function stop (): void
8176 {
82- if (isset ($ this ->args [2 ]) && $ this ->args [2 ] === '--soft-exit ' ) {
83- return ;
84- }
85-
8677 exit ($ this ->exitCode );
8778 }
8879
0 commit comments