create-prisma-php-app 1.3.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,4 +3,6 @@ module.exports = {
3
3
  serveStatic: ["src/app"],
4
4
  files: "src/**/*.*",
5
5
  notify: false,
6
+ open: false,
7
+ ghostMode: false,
6
8
  };
@@ -0,0 +1,53 @@
1
+ const { spawn } = require("child_process");
2
+ const path = require("path");
3
+
4
+ // Define paths
5
+ const phpPath = "php"; // Adjust if necessary to include the full path to PHP
6
+ const serverScriptPath = path.join(
7
+ __dirname,
8
+ "..",
9
+ "src",
10
+ "lib",
11
+ "websocket",
12
+ "server.php"
13
+ );
14
+
15
+ // Hold the server process
16
+ let serverProcess = null;
17
+
18
+ const restartServer = () => {
19
+ // If a server process already exists, kill it
20
+ if (serverProcess) {
21
+ console.log("Stopping WebSocket server...");
22
+ serverProcess.kill("SIGINT"); // Adjust the signal as necessary for your environment
23
+ serverProcess = null;
24
+ }
25
+
26
+ // Start a new WebSocket server process
27
+ console.log("Starting WebSocket server...");
28
+ serverProcess = spawn(phpPath, [serverScriptPath]);
29
+
30
+ serverProcess.stdout.on("data", (data) => {
31
+ console.log(`WebSocket Server: ${data}`);
32
+ });
33
+
34
+ serverProcess.stderr.on("data", (data) => {
35
+ console.error(`WebSocket Server Error: ${data}`);
36
+ });
37
+
38
+ serverProcess.on("close", (code) => {
39
+ console.log(`WebSocket server process exited with code ${code}`);
40
+ });
41
+ };
42
+
43
+ // Initial start
44
+ restartServer();
45
+
46
+ // Watch for changes and restart the server
47
+ const chokidar = require("chokidar");
48
+ chokidar
49
+ .watch(path.join(__dirname, "..", "src", "lib", "websocket", "**", "*"))
50
+ .on("change", (event, path) => {
51
+ console.log(`${event}: ${path}`);
52
+ restartServer();
53
+ });
@@ -0,0 +1,30 @@
1
+ @echo off
2
+ set PORT=8080
3
+ set "PHP_PATH=php"
4
+ set "SERVER_SCRIPT_PATH= src\lib\websocket\server.php"
5
+
6
+ echo [INFO] Checking for processes using port %PORT%...
7
+ netstat -aon | findstr :%PORT%
8
+
9
+ for /f "tokens=5" %%a in ('netstat -aon ^| findstr :%PORT%') do (
10
+ echo [INFO] Found PID: %%a
11
+ taskkill /F /PID %%a
12
+ if %ERRORLEVEL% == 0 (
13
+ echo [SUCCESS] Killed process %%a.
14
+ ) else (
15
+ echo [ERROR] Failed to kill process %%a.
16
+ )
17
+ )
18
+
19
+ :: Ensure the previous command's failure does not prevent the server from starting
20
+ :: Wait a bit to ensure the port is freed
21
+ timeout /t 2
22
+
23
+ :: Start the WebSocket server
24
+ echo [INFO] Starting WebSocket server on port %PORT%...
25
+ %PHP_PATH% %SERVER_SCRIPT_PATH%
26
+ if %ERRORLEVEL% == 0 (
27
+ echo [SUCCESS] WebSocket server started.
28
+ ) else (
29
+ echo [ERROR] Failed to start WebSocket server.
30
+ )
@@ -138,12 +138,9 @@ class StateManager {
138
138
  *
139
139
  * @param {*} update
140
140
  */
141
- setState(update, saveToStorage = false) {
141
+ setState(update) {
142
142
  this.state = { ...this.state, ...update };
143
143
  this.listeners.forEach((listener) => listener(this.state));
144
- if (saveToStorage) {
145
- this.saveState();
146
- }
147
144
  }
148
145
 
149
146
  /**
@@ -0,0 +1,39 @@
1
+ <?php
2
+
3
+ namespace Lib\Websocket;
4
+
5
+ use Ratchet\MessageComponentInterface;
6
+ use Ratchet\ConnectionInterface;
7
+
8
+ class ConnectionManager implements MessageComponentInterface
9
+ {
10
+ protected $clients;
11
+
12
+ public function __construct()
13
+ {
14
+ $this->clients = new \SplObjectStorage;
15
+ }
16
+
17
+ public function onOpen(ConnectionInterface $conn)
18
+ {
19
+ $this->clients->attach($conn);
20
+ echo "New connection! ({$conn->resourceId})\n";
21
+ }
22
+
23
+ public function onMessage(ConnectionInterface $from, $msg)
24
+ {
25
+ // Message handling code
26
+ }
27
+
28
+ public function onClose(ConnectionInterface $conn)
29
+ {
30
+ $this->clients->detach($conn);
31
+ echo "Connection {$conn->resourceId} has disconnected\n";
32
+ }
33
+
34
+ public function onError(ConnectionInterface $conn, \Exception $e)
35
+ {
36
+ echo "An error has occurred: {$e->getMessage()}\n";
37
+ $conn->close();
38
+ }
39
+ }
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ require __DIR__ . '/../../../vendor/autoload.php';
4
+
5
+ use Ratchet\Server\IoServer;
6
+ use Ratchet\Http\HttpServer;
7
+ use Ratchet\WebSocket\WsServer;
8
+ use Lib\Websocket\ConnectionManager;
9
+
10
+ $server = IoServer::factory(
11
+ new HttpServer(
12
+ new WsServer(
13
+ new ConnectionManager()
14
+ )
15
+ ),
16
+ 8080
17
+ );
18
+
19
+ $server->run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",