13
13
14
14
namespace App \Site \Commands \App ;
15
15
16
+ use App \App ;
16
17
use App \Base \Abstracts \Commands \BaseCommand ;
17
18
use DI \DependencyException ;
18
19
use DI \NotFoundException ;
19
20
use Symfony \Component \Console \Input \InputInterface ;
20
21
use Symfony \Component \Console \Output \OutputInterface ;
21
- use Exception ;
22
+ use Throwable ;
22
23
use Symfony \Component \Console \Command \Command ;
23
24
24
25
/**
@@ -47,6 +48,8 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
47
48
{
48
49
$ this ->getIo ()->title ('Welcome. ' );
49
50
51
+ $ app = App::getInstance ();
52
+
50
53
$ history = [];
51
54
do {
52
55
$ command = rtrim (trim ($ this ->keepAsking ("\n> " )), '; ' );
@@ -59,11 +62,14 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
59
62
case 'exit ' :
60
63
$ command = 'exit ' ;
61
64
break ;
65
+ case 'help ' :
66
+ $ this ->renderHelp ();
67
+ break ;
62
68
default :
63
69
try {
64
70
eval ($ command . '; ' );
65
71
$ history [] = $ command ;
66
- } catch (Exception $ e ) {
72
+ } catch (Throwable $ e ) {
67
73
$ output ->writeln ($ e ->getMessage ());
68
74
}
69
75
break ;
@@ -73,4 +79,24 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
73
79
74
80
return Command::SUCCESS ;
75
81
}
82
+
83
+ protected function renderHelp ()
84
+ {
85
+ $ this ->getIo ()->writeln (
86
+ " =============================================== \n" .
87
+ " PHP Interactive Shell \n" .
88
+ " =============================================== \n\n" .
89
+ " Welcome to the Interactive Shell. \n\n" .
90
+ " - You can execute any valid PHP code directly. \n" .
91
+ " - Use 'history' to view the list of previously executed commands. \n" .
92
+ " - Use 'quit' or 'exit' to leave the shell. \n" .
93
+ " - Use 'help' to display this message again. \n\n" .
94
+ " Current Variables: \n" .
95
+ " - \$this: The current command instance. \n" .
96
+ " - \$output: The output interface for writing messages. \n" .
97
+ " - \$input: The input interface for reading user input. \n" .
98
+ " - \$app: An application reference. \n" .
99
+ " =============================================== "
100
+ );
101
+ }
76
102
}
0 commit comments