create-prisma-php-app 4.0.0-alpha.5 → 4.0.0-alpha.51

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.
Files changed (53) hide show
  1. package/dist/.htaccess +54 -41
  2. package/dist/bootstrap.php +142 -97
  3. package/dist/index.js +819 -343
  4. package/dist/settings/auto-swagger-docs.ts +196 -95
  5. package/dist/settings/bs-config.ts +53 -58
  6. package/dist/settings/files-list.json +1 -1
  7. package/dist/settings/project-name.ts +2 -0
  8. package/dist/settings/restart-mcp.ts +58 -0
  9. package/dist/settings/restart-websocket.ts +51 -45
  10. package/dist/settings/utils.ts +240 -0
  11. package/dist/src/Lib/AI/ChatGPTClient.php +147 -0
  12. package/dist/src/Lib/Auth/Auth.php +544 -0
  13. package/dist/src/Lib/Auth/AuthConfig.php +89 -0
  14. package/dist/src/Lib/CacheHandler.php +121 -0
  15. package/dist/src/Lib/ErrorHandler.php +322 -0
  16. package/dist/src/Lib/FileManager/UploadFile.php +383 -0
  17. package/dist/src/Lib/Headers/Boom.php +192 -0
  18. package/dist/src/Lib/IncludeTracker.php +59 -0
  19. package/dist/src/Lib/MCP/WeatherTools.php +104 -0
  20. package/dist/src/Lib/MCP/mcp-server.php +80 -0
  21. package/dist/src/Lib/MainLayout.php +230 -0
  22. package/dist/src/Lib/Middleware/AuthMiddleware.php +157 -0
  23. package/dist/src/Lib/Middleware/CorsMiddleware.php +145 -0
  24. package/dist/src/Lib/PHPMailer/Mailer.php +169 -0
  25. package/dist/src/Lib/PartialRenderer.php +40 -0
  26. package/dist/src/Lib/PrismaPHPSettings.php +181 -0
  27. package/dist/src/Lib/Request.php +479 -0
  28. package/dist/src/Lib/Security/RateLimiter.php +33 -0
  29. package/dist/src/Lib/Set.php +102 -0
  30. package/dist/src/Lib/StateManager.php +127 -0
  31. package/dist/src/Lib/Validator.php +752 -0
  32. package/dist/src/{Websocket → Lib/Websocket}/ConnectionManager.php +1 -1
  33. package/dist/src/Lib/Websocket/websocket-server.php +118 -0
  34. package/dist/src/app/error.php +1 -1
  35. package/dist/src/app/index.php +22 -5
  36. package/dist/src/app/js/index.js +1 -1
  37. package/dist/src/app/layout.php +2 -2
  38. package/package.json +1 -1
  39. package/dist/settings/restart-websocket.bat +0 -28
  40. package/dist/src/app/assets/images/prisma-php-black.svg +0 -6
  41. package/dist/websocket-server.php +0 -22
  42. package/vendor/autoload.php +0 -25
  43. package/vendor/composer/ClassLoader.php +0 -579
  44. package/vendor/composer/InstalledVersions.php +0 -359
  45. package/vendor/composer/LICENSE +0 -21
  46. package/vendor/composer/autoload_classmap.php +0 -10
  47. package/vendor/composer/autoload_namespaces.php +0 -9
  48. package/vendor/composer/autoload_psr4.php +0 -10
  49. package/vendor/composer/autoload_real.php +0 -38
  50. package/vendor/composer/autoload_static.php +0 -25
  51. package/vendor/composer/installed.json +0 -825
  52. package/vendor/composer/installed.php +0 -132
  53. package/vendor/composer/platform_check.php +0 -26
@@ -0,0 +1,127 @@
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ namespace Lib;
6
+
7
+ use Lib\Request;
8
+
9
+ class StateManager
10
+ {
11
+ private const APP_STATE = 'app_state_F989A';
12
+ private static array $state = [];
13
+ private static array $listeners = [];
14
+
15
+ public static function init(): void
16
+ {
17
+ self::loadState();
18
+
19
+ if (!Request::$isWire) {
20
+ self::resetState();
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Gets the state value for the specified key.
26
+ *
27
+ * @param string|null $key The key of the state value to get.
28
+ * @param mixed $initialValue The initial value to set if the key does not exist.
29
+ * @return mixed The state value for the specified key.
30
+ */
31
+ public static function getState(?string $key = null, mixed $initialValue = null): mixed
32
+ {
33
+ if ($key === null) {
34
+ return new \ArrayObject(self::$state, \ArrayObject::ARRAY_AS_PROPS);
35
+ }
36
+
37
+ $value = self::$state[$key] ?? $initialValue;
38
+
39
+ return is_array($value) ? new \ArrayObject($value, \ArrayObject::ARRAY_AS_PROPS) : $value;
40
+ }
41
+
42
+ /**
43
+ * Sets the state value for the specified key.
44
+ *
45
+ * @param string $key The key of the state value to set.
46
+ * @param mixed $value The value to set.
47
+ */
48
+ public static function setState(string $key, mixed $value = null): void
49
+ {
50
+ if (array_key_exists($key, $GLOBALS)) {
51
+ $GLOBALS[$key] = $value;
52
+ }
53
+
54
+ self::$state[$key] = $value;
55
+
56
+ self::notifyListeners();
57
+ self::saveState();
58
+ }
59
+
60
+ /**
61
+ * Subscribes a listener to state changes.
62
+ *
63
+ * @param callable $listener The listener function to subscribe.
64
+ * @return callable A function that can be called to unsubscribe the listener.
65
+ */
66
+ public static function subscribe(callable $listener): callable
67
+ {
68
+ self::$listeners[] = $listener;
69
+ $listener(self::$state);
70
+ return fn() => self::$listeners = array_filter(self::$listeners, fn($l) => $l !== $listener);
71
+ }
72
+
73
+ /**
74
+ * Saves the current state to storage.
75
+ */
76
+ private static function saveState(): void
77
+ {
78
+ $_SESSION[self::APP_STATE] = json_encode(self::$state, JSON_THROW_ON_ERROR);
79
+ }
80
+
81
+ /**
82
+ * Loads the state from storage, if available.
83
+ */
84
+ public static function loadState(): void
85
+ {
86
+ if (isset($_SESSION[self::APP_STATE])) {
87
+ $loadedState = json_decode($_SESSION[self::APP_STATE], true, 512, JSON_THROW_ON_ERROR);
88
+ if (is_array($loadedState)) {
89
+ self::$state = $loadedState;
90
+ self::notifyListeners();
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Resets the application state to an empty array.
97
+ *
98
+ * @param string|null $key The key of the state value to reset.
99
+ */
100
+ public static function resetState(?string $key = null): void
101
+ {
102
+ if ($key !== null) {
103
+ if (array_key_exists($key, self::$state)) {
104
+ self::$state[$key] = null;
105
+
106
+ if (array_key_exists($key, $GLOBALS)) {
107
+ $GLOBALS[$key] = null;
108
+ }
109
+ }
110
+ } else {
111
+ self::$state = [];
112
+ }
113
+
114
+ self::notifyListeners();
115
+ self::saveState();
116
+ }
117
+
118
+ /**
119
+ * Notifies all listeners of state changes.
120
+ */
121
+ private static function notifyListeners(): void
122
+ {
123
+ foreach (self::$listeners as $listener) {
124
+ $listener(self::$state);
125
+ }
126
+ }
127
+ }