1111
1212namespace Litipk \JupyterPHP \Handlers ;
1313
14-
1514use Litipk \JupyterPHP \Actions \ExecuteAction ;
1615use Litipk \JupyterPHP \Actions \HistoryAction ;
1716use Litipk \JupyterPHP \Actions \KernelInfoAction ;
2322use Psy \Shell ;
2423use React \ZMQ \SocketWrapper ;
2524
26-
2725final class ShellMessagesHandler
2826{
2927 /** @var ExecuteAction */
@@ -46,23 +44,25 @@ final class ShellMessagesHandler
4644
4745
4846 public function __construct (
49- JupyterBroker $ broker , SocketWrapper $ iopubSocket , SocketWrapper $ shellSocket , Logger $ logger
50- )
51- {
47+ JupyterBroker $ broker ,
48+ SocketWrapper $ iopubSocket ,
49+ SocketWrapper $ shellSocket ,
50+ Logger $ logger
51+ ) {
5252 $ this ->shellSoul = new Shell ();
53-
53+
5454 $ this ->executeAction = new ExecuteAction ($ broker , $ iopubSocket , $ shellSocket , $ this ->shellSoul );
5555 $ this ->historyAction = new HistoryAction ($ broker , $ shellSocket );
5656 $ this ->kernelInfoAction = new KernelInfoAction ($ broker , $ shellSocket , $ iopubSocket );
57- $ this ->shutdownAction = new ShutdownAction ($ broker , $ shellSocket );
58-
57+ $ this ->shutdownAction = new ShutdownAction ($ broker , $ iopubSocket , $ shellSocket );
58+
5959 $ this ->logger = $ logger ;
6060
6161 $ broker ->send (
6262 $ iopubSocket , 'status ' , ['execution_state ' => 'starting ' ], []
6363 );
6464
65- $ this ->shellSoul ->setOutput ( new KernelOutput ($ this ->executeAction , $ this ->logger ->withName ('KernelOutput ' )));
65+ $ this ->shellSoul ->setOutput (new KernelOutput ($ this ->executeAction , $ this ->logger ->withName ('KernelOutput ' )));
6666 }
6767
6868 public function __invoke (array $ msg )
@@ -73,24 +73,24 @@ public function __invoke(array $msg)
7373 $ content = json_decode ($ content , true );
7474
7575 $ this ->logger ->debug ('Received message ' , [
76- 'processId ' => getmypid (),
77- 'zmqId ' => $ zmqId ,
78- 'delim ' => $ delim ,
79- 'hmac ' => $ hmac ,
80- 'header ' => $ header ,
76+ 'processId ' => getmypid (),
77+ 'zmqId ' => htmlentities ( $ zmqId, ENT_COMPAT , " UTF-8 " ) ,
78+ 'delim ' => $ delim ,
79+ 'hmac ' => $ hmac ,
80+ 'header ' => $ header ,
8181 'parentHeader ' => $ parentHeader ,
82- 'metadata ' => $ metadata ,
83- 'content ' => $ content
82+ 'metadata ' => $ metadata ,
83+ 'content ' => $ content
8484 ]);
8585
8686 if ('kernel_info_request ' === $ header ['msg_type ' ]) {
87- $ this ->kernelInfoAction ->call ($ header , $ content );
87+ $ this ->kernelInfoAction ->call ($ header , $ content, $ zmqId );
8888 } elseif ('execute_request ' === $ header ['msg_type ' ]) {
89- $ this ->executeAction ->call ($ header , $ content );
89+ $ this ->executeAction ->call ($ header , $ content, $ zmqId );
9090 } elseif ('history_request ' === $ header ['msg_type ' ]) {
91- $ this ->historyAction ->call ($ header , $ content );
91+ $ this ->historyAction ->call ($ header , $ content, $ zmqId );
9292 } elseif ('shutdown_request ' === $ header ['msg_type ' ]) {
93- $ this ->shutdownAction ->call ($ header , $ content );
93+ $ this ->shutdownAction ->call ($ header , $ content, $ zmqId );
9494 } elseif ('comm_open ' === $ header ['msg_type ' ]) {
9595 // TODO: Research about what should be done.
9696 } else {
0 commit comments