1- <?php
1+ <?php declare (strict_types= 1 );
22
33namespace Bref \Cli \Tinker ;
44
1212use Psy \Shell ;
1313use Symfony \Contracts \HttpClient \Exception \ExceptionInterface ;
1414use Symfony \Contracts \HttpClient \Exception \HttpExceptionInterface ;
15+ use Throwable ;
1516use function Amp \delay ;
1617
1718class BrefTinkerLoopListener extends AbstractListener
1819{
19- /**
20- * @var array{appName: string, environmentName: string, team: string}
21- */
22- protected array $ brefConfig ;
23-
24- /**
25- * @var array{
26- * id: int,
27- * name: string,
28- * region: string|null,
29- * url: string|null,
30- * outputs: array<string, string>,
31- * app: array{id: int, name: string},
32- * }
33- */
34- protected array $ environment ;
35-
36- protected BrefCloudClient $ brefCloudClient ;
37-
38- /**
39- * @param array<string, string> $brefConfig
40- * @throws ExceptionInterface
41- * @throws HttpExceptionInterface
42- */
43- public function __construct (array $ brefConfig )
20+ public function __construct (
21+ private readonly int $ environmentId ,
22+ private readonly BrefCloudClient $ brefCloudClient ,
23+ )
4424 {
45- $ this ->brefConfig = $ brefConfig ;
46- [
47- 'appName ' => $ appName ,
48- 'environmentName ' => $ environmentName ,
49- 'team ' => $ team ,
50- ] = $ brefConfig ;
51- $ this ->brefCloudClient = new BrefCloudClient ;
52- $ this ->environment = $ this ->brefCloudClient ->findEnvironment ($ team , $ appName , $ environmentName );
5325 }
5426
5527 public static function isSupported (): bool
@@ -64,7 +36,7 @@ public static function isSupported(): bool
6436 */
6537 public function onExecute (Shell $ shell , string $ code )
6638 {
67- if ($ code == '\Psy\Exception\BreakException::exitShell(); ' ) {
39+ if ($ code === '\Psy\Exception\BreakException::exitShell(); ' ) {
6840 return $ code ;
6941 }
7042
@@ -94,16 +66,15 @@ public function onExecute(Shell $shell, string $code)
9466 if (!empty ($ context )) {
9567 // Extract _context into shell's scope variables for next code execution
9668 // Return NoValue as output and return value were printed out
97- return "extract(['_context' => ' {$ context }']); return new \Psy\CodeCleaner\NoReturnValue(); " ;
98- } else {
99- // Return NoValue as output and return value were printed out
100- return "return new \Psy\CodeCleaner\NoReturnValue(); " ;
69+ return "extract(['_context' => ' $ context']); return new \Psy\CodeCleaner\NoReturnValue(); " ;
10170 }
71+ // Return NoValue as output and return value were printed out
72+ return "return new \Psy\CodeCleaner\NoReturnValue(); " ;
10273 }
10374
10475 return ExecutionClosure::NOOP_INPUT ;
105- } catch (\ Throwable $ _e ) {
106- throw new BreakException ($ _e ->getMessage ());
76+ } catch (Throwable $ e ) {
77+ throw new BreakException ($ e ->getMessage ());
10778 }
10879 }
10980
@@ -119,7 +90,7 @@ protected function evaluateCode(string $code, string $context): array
11990 '--execute=\" ' .base64_encode ($ code ).'\" ' ,
12091 '--context=\" ' .$ context .'\" ' ,
12192 ]);
122- $ id = $ this ->brefCloudClient ->startCommand ($ this ->environment [ ' id ' ] , $ command );
93+ $ id = $ this ->brefCloudClient ->startCommand ($ this ->environmentId , $ command );
12394
12495 // Timeout after 2 minutes and 10 seconds
12596 $ timeout = 130 ;
0 commit comments