3
3
4
4
namespace Litipk \JupyterPHP \Actions ;
5
5
6
-
7
6
use Litipk \JupyterPHP \JupyterBroker ;
8
7
use Psy \Exception \BreakException ;
9
8
use Psy \Exception \ThrowUpException ;
10
9
use Psy \ExecutionLoop \Loop ;
11
10
use Psy \Shell ;
12
11
use React \ZMQ \SocketWrapper ;
13
12
14
-
15
13
final class ExecuteAction implements Action
16
14
{
17
15
/** @var JupyterBroker */
@@ -31,9 +29,12 @@ final class ExecuteAction implements Action
31
29
32
30
/** @var string */
33
31
private $ code ;
34
-
32
+
33
+ /** @var bool */
34
+ private $ silent ;
35
+
35
36
/** @var int */
36
- private $ execCount ;
37
+ private $ execCount = 0 ;
37
38
38
39
/**
39
40
* ExecuteAction constructor.
@@ -43,9 +44,11 @@ final class ExecuteAction implements Action
43
44
* @param Shell $shellSoul
44
45
*/
45
46
public function __construct (
46
- JupyterBroker $ broker , SocketWrapper $ iopubSocket , SocketWrapper $ shellSocket , Shell $ shellSoul
47
- )
48
- {
47
+ JupyterBroker $ broker ,
48
+ SocketWrapper $ iopubSocket ,
49
+ SocketWrapper $ shellSocket ,
50
+ Shell $ shellSoul
51
+ ) {
49
52
$ this ->broker = $ broker ;
50
53
$ this ->iopubSocket = $ iopubSocket ;
51
54
$ this ->shellSocket = $ shellSocket ;
@@ -54,32 +57,50 @@ public function __construct(
54
57
55
58
public function call (array $ header , array $ content , $ zmqId = null )
56
59
{
57
- $ this ->broker ->send (
58
- $ this ->iopubSocket , 'status ' , ['execution_state ' => 'busy ' ], $ header
59
- );
60
+ $ this ->broker ->send ($ this ->iopubSocket , 'status ' , ['execution_state ' => 'busy ' ], $ header );
60
61
61
62
$ this ->header = $ header ;
62
- $ this ->execCount = isset ($ content ->execution_count ) ? $ content ->execution_count : 0 ;
63
63
$ this ->code = $ content ['code ' ];
64
+ $ this ->silent = $ content ['silent ' ];
65
+
66
+ if (!$ this ->silent ) {
67
+ $ this ->execCount = $ this ->execCount + 1 ;
68
+
69
+ $ this ->broker ->send (
70
+ $ this ->iopubSocket ,
71
+ 'execute_input ' ,
72
+ ['code ' => $ this ->code , 'execution_count ' => $ this ->execCount ],
73
+ $ this ->header
74
+ );
75
+ }
64
76
65
77
$ closure = $ this ->getClosure ();
66
78
$ closure ();
79
+
80
+ $ replyContent = [
81
+ 'status ' => 'ok ' ,
82
+ 'execution_count ' => $ this ->execCount ,
83
+ 'payload ' => [],
84
+ 'user_expressions ' => new \stdClass
85
+ ];
86
+
87
+ $ this ->broker ->send ($ this ->shellSocket , 'execute_reply ' , $ replyContent , $ this ->header , [], $ zmqId );
88
+
89
+ $ this ->broker ->send ($ this ->iopubSocket , 'status ' , ['execution_state ' => 'idle ' ], $ this ->header );
67
90
}
68
91
69
92
/**
70
93
* @param string $message
71
94
*/
72
95
public function notifyMessage ($ message )
73
96
{
74
- $ this ->broker ->send ($ this ->shellSocket , 'execute_reply ' , ['status ' => 'ok ' ], $ this ->header );
75
- $ this ->broker ->send ($ this ->iopubSocket , 'stream ' , ['name ' => 'stdout ' , 'data ' => $ message ], $ this ->header );
97
+ $ this ->broker ->send ($ this ->iopubSocket , 'stream ' , ['name ' => 'stdout ' , 'text ' => $ message ], $ this ->header );
76
98
$ this ->broker ->send (
77
99
$ this ->iopubSocket ,
78
100
'execute_result ' ,
79
- ['execution_count ' => $ this ->execCount + 1 , 'data ' => $ message , 'metadata ' => new \stdClass ],
101
+ ['execution_count ' => $ this ->execCount , 'data ' => [ ' text/plain ' => $ message] , 'metadata ' => new \stdClass ],
80
102
$ this ->header
81
103
);
82
- $ this ->broker ->send ($ this ->iopubSocket , 'status ' , ['execution_state ' => 'idle ' ], $ this ->header );
83
104
}
84
105
85
106
/**
0 commit comments