33
44namespace Litipk \JupyterPHP \Actions ;
55
6-
76use Litipk \JupyterPHP \JupyterBroker ;
87use Psy \Exception \BreakException ;
98use Psy \Exception \ThrowUpException ;
109use Psy \ExecutionLoop \Loop ;
1110use Psy \Shell ;
1211use React \ZMQ \SocketWrapper ;
1312
14-
1513final class ExecuteAction implements Action
1614{
1715 /** @var JupyterBroker */
@@ -31,9 +29,12 @@ final class ExecuteAction implements Action
3129
3230 /** @var string */
3331 private $ code ;
34-
32+
33+ /** @var bool */
34+ private $ silent ;
35+
3536 /** @var int */
36- private $ execCount ;
37+ private $ execCount = 0 ;
3738
3839 /**
3940 * ExecuteAction constructor.
@@ -43,9 +44,11 @@ final class ExecuteAction implements Action
4344 * @param Shell $shellSoul
4445 */
4546 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+ ) {
4952 $ this ->broker = $ broker ;
5053 $ this ->iopubSocket = $ iopubSocket ;
5154 $ this ->shellSocket = $ shellSocket ;
@@ -54,32 +57,50 @@ public function __construct(
5457
5558 public function call (array $ header , array $ content , $ zmqId = null )
5659 {
57- $ this ->broker ->send (
58- $ this ->iopubSocket , 'status ' , ['execution_state ' => 'busy ' ], $ header
59- );
60+ $ this ->broker ->send ($ this ->iopubSocket , 'status ' , ['execution_state ' => 'busy ' ], $ header );
6061
6162 $ this ->header = $ header ;
62- $ this ->execCount = isset ($ content ->execution_count ) ? $ content ->execution_count : 0 ;
6363 $ 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+ }
6476
6577 $ closure = $ this ->getClosure ();
6678 $ 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 );
6790 }
6891
6992 /**
7093 * @param string $message
7194 */
7295 public function notifyMessage ($ message )
7396 {
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 );
7698 $ this ->broker ->send (
7799 $ this ->iopubSocket ,
78100 '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 ],
80102 $ this ->header
81103 );
82- $ this ->broker ->send ($ this ->iopubSocket , 'status ' , ['execution_state ' => 'idle ' ], $ this ->header );
83104 }
84105
85106 /**
0 commit comments