Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 298d460

Browse files
committed
A lot of work (based on dawehner/jupyter-php)
1 parent 324751d commit 298d460

13 files changed

+345
-3
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"type": "project",
55
"license": "MIT",
66
"require": {
7-
"php": "5.*,>=5.4",
7+
"php": ">=5.5.9",
88
"ext-zmq": "*",
9-
"psy/psysh": "0.6.*",
10-
"composer/composer": "1.0.0-alpha11"
9+
"psy/psysh": "0.7.*",
10+
"composer/composer": "1.0.0-alpha11",
11+
"react/zmq": "^0.3.0",
12+
"ramsey/uuid": "^3.2"
1113
},
1214
"require-dev": {
1315

File renamed without changes.

src/Actions/HistoryAction.php

Whitespace-only changes.

src/Actions/KernelInfoAction.php

Whitespace-only changes.

src/Actions/ShutdownAction.php

Whitespace-only changes.

src/ConnectionSettings.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
4+
namespace Litipk\JupyterPHP;
5+
6+
7+
final class ConnectionSettings
8+
{
9+
/**
10+
* @return array[string]mixed
11+
*/
12+
public static function get()
13+
{
14+
global $argv;
15+
if (!isset($argv) || empty($argv)) {
16+
$argv = $_SERVER['argv'];
17+
}
18+
19+
if (is_array($argv) && count($argv) > 1) {
20+
$connectionFileContents = file_get_contents($argv[1], false, true, 0, 2048);
21+
22+
if (false === $connectionFileContents) {
23+
throw new \RuntimeException('Connection Settings: Unable to open the connection file.');
24+
}
25+
26+
$connectionSettings = json_decode($connectionFileContents);
27+
28+
if (json_last_error() !== JSON_ERROR_NONE) {
29+
throw new \RuntimeException('Connection Settings: Corrupted connection file.');
30+
}
31+
32+
return $connectionSettings;
33+
} else {
34+
throw new \RuntimeException('Connection Settings: Not specified.');
35+
}
36+
}
37+
38+
/**
39+
* @param null|array $connectionSettings
40+
* @return array[string]string
41+
*/
42+
public static function getConnectionUris(array $connectionSettings = null)
43+
{
44+
if (null === $connectionSettings) {
45+
$connectionSettings = self::get();
46+
}
47+
48+
$connectionUri = $connectionSettings['transport'].'://'.$connectionSettings['ip'].':';
49+
50+
return [
51+
'stdin' => $connectionUri.$connectionSettings['stdin_port'],
52+
'control' => $connectionUri.$connectionSettings['control_port'],
53+
'hb' => $connectionUri.$connectionSettings['hb_port'],
54+
'shell' => $connectionUri.$connectionSettings['shell_port'],
55+
'iopub' => $connectionUri.$connectionSettings['iopub_port']
56+
];
57+
}
58+
}

src/Handlers/HbErrorHandler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Litipk\JupyterPHP\Handlers;
4+
5+
6+
class HbErrorHandler
7+
{
8+
public function __invoke($e)
9+
{
10+
}
11+
}

src/Handlers/HbMessagesHandler.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
4+
namespace Litipk\JupyterPHP\Handlers;
5+
6+
7+
final class HbMessagesHandler
8+
{
9+
public function __invoke($msg)
10+
{
11+
12+
}
13+
}

src/Handlers/IOPubMessagesHandler.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
4+
namespace Litipk\JupyterPHP\Handlers;
5+
6+
7+
final class IOPubMessagesHandler
8+
{
9+
public function __invoke($msg)
10+
{
11+
12+
}
13+
}

src/Handlers/ShellMessagesHandler.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
4+
namespace Litipk\JupyterPHP\Handlers;
5+
6+
7+
final class ShellMessagesHandler
8+
{
9+
public function __invoke($msg)
10+
{
11+
list($zmqId, $delim, $hmac, $header, $parent_header, $metadata, $content) = $msg;
12+
13+
$header = json_decode($header);
14+
$content = json_decode($content);
15+
16+
if ('kernel_info_request' === $header->msg_type) {
17+
18+
} elseif ('execute_request' === $header->msg_type) {
19+
20+
} elseif ('history_request' === $header->msg_type) {
21+
22+
} elseif ('shutdown_request' === $header->msg_type) {
23+
24+
} else {
25+
// TODO: Add logger!
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)