11
11
12
12
namespace Litipk \JupyterPHP \Handlers ;
13
13
14
-
15
14
use Litipk \JupyterPHP \Actions \ExecuteAction ;
16
15
use Litipk \JupyterPHP \Actions \HistoryAction ;
17
16
use Litipk \JupyterPHP \Actions \KernelInfoAction ;
23
22
use Psy \Shell ;
24
23
use React \ZMQ \SocketWrapper ;
25
24
26
-
27
25
final class ShellMessagesHandler
28
26
{
29
27
/** @var ExecuteAction */
@@ -46,23 +44,25 @@ final class ShellMessagesHandler
46
44
47
45
48
46
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
+ ) {
52
52
$ this ->shellSoul = new Shell ();
53
-
53
+
54
54
$ this ->executeAction = new ExecuteAction ($ broker , $ iopubSocket , $ shellSocket , $ this ->shellSoul );
55
55
$ this ->historyAction = new HistoryAction ($ broker , $ shellSocket );
56
56
$ this ->kernelInfoAction = new KernelInfoAction ($ broker , $ shellSocket , $ iopubSocket );
57
- $ this ->shutdownAction = new ShutdownAction ($ broker , $ shellSocket );
58
-
57
+ $ this ->shutdownAction = new ShutdownAction ($ broker , $ iopubSocket , $ shellSocket );
58
+
59
59
$ this ->logger = $ logger ;
60
60
61
61
$ broker ->send (
62
62
$ iopubSocket , 'status ' , ['execution_state ' => 'starting ' ], []
63
63
);
64
64
65
- $ this ->shellSoul ->setOutput ( new KernelOutput ($ this ->executeAction , $ this ->logger ->withName ('KernelOutput ' )));
65
+ $ this ->shellSoul ->setOutput (new KernelOutput ($ this ->executeAction , $ this ->logger ->withName ('KernelOutput ' )));
66
66
}
67
67
68
68
public function __invoke (array $ msg )
@@ -73,24 +73,24 @@ public function __invoke(array $msg)
73
73
$ content = json_decode ($ content , true );
74
74
75
75
$ 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 ,
81
81
'parentHeader ' => $ parentHeader ,
82
- 'metadata ' => $ metadata ,
83
- 'content ' => $ content
82
+ 'metadata ' => $ metadata ,
83
+ 'content ' => $ content
84
84
]);
85
85
86
86
if ('kernel_info_request ' === $ header ['msg_type ' ]) {
87
- $ this ->kernelInfoAction ->call ($ header , $ content );
87
+ $ this ->kernelInfoAction ->call ($ header , $ content, $ zmqId );
88
88
} elseif ('execute_request ' === $ header ['msg_type ' ]) {
89
- $ this ->executeAction ->call ($ header , $ content );
89
+ $ this ->executeAction ->call ($ header , $ content, $ zmqId );
90
90
} elseif ('history_request ' === $ header ['msg_type ' ]) {
91
- $ this ->historyAction ->call ($ header , $ content );
91
+ $ this ->historyAction ->call ($ header , $ content, $ zmqId );
92
92
} elseif ('shutdown_request ' === $ header ['msg_type ' ]) {
93
- $ this ->shutdownAction ->call ($ header , $ content );
93
+ $ this ->shutdownAction ->call ($ header , $ content, $ zmqId );
94
94
} elseif ('comm_open ' === $ header ['msg_type ' ]) {
95
95
// TODO: Research about what should be done.
96
96
} else {
0 commit comments