create-prisma-php-app 1.9.15 → 1.9.17
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.
- package/composer.json +2 -1
- package/dist/.htaccess +5 -10
- package/dist/bootstrap.php +124 -51
- package/dist/index.js +1 -714
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-client-php/index.js +11 -11
- package/dist/settings/project-name.cjs +48 -21
- package/dist/settings/request-methods.php +16 -0
- package/dist/settings/route-request.php +31 -0
- package/dist/src/Lib/Auth/Auth.php +163 -0
- package/dist/src/Lib/Auth/AuthConfig.php +59 -0
- package/dist/src/Lib/Middleware/AuthMiddleware.php +91 -0
- package/dist/src/Lib/StateManager.php +110 -0
- package/dist/src/app/index.php +5 -2
- package/package.json +1 -1
- package/composer-websocket.lock +0 -1993
- package/dist/bootstrap-ajax.php +0 -142
- /package/dist/settings/{restart_websocket.bat → restart-websocket.bat} +0 -0
- /package/dist/settings/{restartWebsocket.cjs → restart-websocket.cjs} +0 -0
package/dist/bootstrap-ajax.php
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
header('Content-Type: application/json');
|
|
4
|
-
|
|
5
|
-
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
|
6
|
-
header('HTTP/1.1 200 OK');
|
|
7
|
-
exit;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (empty($_SERVER["HTTP_X_REQUESTED_WITH"]) || $_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
|
|
11
|
-
header("HTTP/1.0 400 Bad Request");
|
|
12
|
-
echo json_encode(["error" => "Invalid request method or type."]);
|
|
13
|
-
exit;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Determine the request method
|
|
17
|
-
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
|
18
|
-
$allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
19
|
-
|
|
20
|
-
if (!in_array($requestMethod, $allowedMethods)) {
|
|
21
|
-
echo "Method not allowed\n";
|
|
22
|
-
header("HTTP/1.1 405 Method Not Allowed");
|
|
23
|
-
exit;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
$isGet = $requestMethod === 'GET';
|
|
27
|
-
$isPost = $requestMethod === 'POST';
|
|
28
|
-
$isPut = $requestMethod === 'PUT';
|
|
29
|
-
$isDelete = $requestMethod === 'DELETE';
|
|
30
|
-
$isPatch = $requestMethod === 'PATCH';
|
|
31
|
-
$isHead = $requestMethod === 'HEAD';
|
|
32
|
-
$isOptions = $requestMethod === 'OPTIONS';
|
|
33
|
-
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
|
34
|
-
$params = [];
|
|
35
|
-
|
|
36
|
-
if (stripos($contentType, 'application/json') !== false) {
|
|
37
|
-
$jsonInput = file_get_contents('php://input');
|
|
38
|
-
if (!empty($jsonInput)) {
|
|
39
|
-
$data = json_decode($jsonInput, true);
|
|
40
|
-
if (json_last_error() === JSON_ERROR_NONE) {
|
|
41
|
-
$params = $data;
|
|
42
|
-
} else {
|
|
43
|
-
echo json_encode(['error' => 'Error: Invalid JSON body!']);
|
|
44
|
-
exit;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
$scriptUrl = $_SERVER['REQUEST_URI'];
|
|
50
|
-
$scriptUrl = explode('?', $scriptUrl, 2)[0];
|
|
51
|
-
$uri = $_SERVER['SCRIPT_URL'] ?? uriExtractor($scriptUrl);
|
|
52
|
-
|
|
53
|
-
// Check for private directory access
|
|
54
|
-
if (strpos($uri, '/_') !== false || strpos($uri, '_') === 0) {
|
|
55
|
-
handleNotFound();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
$baseDir = __DIR__;
|
|
59
|
-
|
|
60
|
-
require_once $baseDir . "/settings/paths.php";
|
|
61
|
-
require_once $baseDir . "/vendor/autoload.php";
|
|
62
|
-
|
|
63
|
-
$groupFolder = findGroupFolder($uri);
|
|
64
|
-
$filePath = $baseDir . '/src/app' . $groupFolder;
|
|
65
|
-
|
|
66
|
-
if (basename($filePath) === 'route.php' && file_exists($filePath)) {
|
|
67
|
-
require_once($filePath);
|
|
68
|
-
} else {
|
|
69
|
-
handleNotFound();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function uriExtractor(string $scriptUrl): string
|
|
73
|
-
{
|
|
74
|
-
$prismaPHPSettings = json_decode(file_get_contents("prisma-php.json"), true);
|
|
75
|
-
$projectName = $prismaPHPSettings['projectName'] ?? '';
|
|
76
|
-
if (empty($projectName)) {
|
|
77
|
-
return "/";
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
$escapedIdentifier = preg_quote($projectName, '/');
|
|
81
|
-
$pattern = "/(?:{$escapedIdentifier})(\/.+?)(?=\/{$escapedIdentifier}\/|$)/";
|
|
82
|
-
|
|
83
|
-
if (preg_match_all($pattern, $scriptUrl, $matches, PREG_SET_ORDER)) {
|
|
84
|
-
$lastMatch = end($matches);
|
|
85
|
-
if (!empty($lastMatch[1])) {
|
|
86
|
-
return $lastMatch[1];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return "/";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function handleNotFound()
|
|
94
|
-
{
|
|
95
|
-
header("HTTP/1.0 404 Not Found");
|
|
96
|
-
echo json_encode(['error' => 'Not Found', 'message' => 'The requested resource was not found.']);
|
|
97
|
-
exit;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function findGroupFolder($uri): string
|
|
101
|
-
{
|
|
102
|
-
$uriSegments = explode('/', $uri);
|
|
103
|
-
foreach ($uriSegments as $segment) {
|
|
104
|
-
if (!empty($segment)) {
|
|
105
|
-
if (isGroupIdentifier($segment)) {
|
|
106
|
-
return $segment;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
$matchedGroupFolder = matchGroupFolder($uri);
|
|
112
|
-
if ($matchedGroupFolder) {
|
|
113
|
-
return $matchedGroupFolder;
|
|
114
|
-
} else {
|
|
115
|
-
return '';
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function isGroupIdentifier($segment): bool
|
|
120
|
-
{
|
|
121
|
-
return preg_match('/^\(.*\)$/', $segment);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function matchGroupFolder($constructedPath): ?string
|
|
125
|
-
{
|
|
126
|
-
$routes = json_decode(file_get_contents(SETTINGS_PATH . "/files-list.json"), true);
|
|
127
|
-
$bestMatch = null;
|
|
128
|
-
$normalizedConstructedPath = ltrim(str_replace('\\', '/', $constructedPath), './');
|
|
129
|
-
|
|
130
|
-
$normalizedConstructedPath = "/$normalizedConstructedPath/route.php";
|
|
131
|
-
|
|
132
|
-
foreach ($routes as $route) {
|
|
133
|
-
$normalizedRoute = trim(str_replace('\\', '/', $route), '.');
|
|
134
|
-
$cleanedRoute = preg_replace('/\/\([^)]+\)/', '', $normalizedRoute);
|
|
135
|
-
if ($cleanedRoute === $normalizedConstructedPath) {
|
|
136
|
-
$bestMatch = $normalizedRoute;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return $bestMatch;
|
|
142
|
-
}
|
|
File without changes
|
|
File without changes
|