create-prisma-php-app 1.7.10 → 1.8.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.
package/dist/bootstrap.php
CHANGED
|
@@ -24,14 +24,28 @@ function determineContentToInclude()
|
|
|
24
24
|
$includePath = '';
|
|
25
25
|
$metadata = $metadata[$uri] ?? $metadata['default'];
|
|
26
26
|
|
|
27
|
+
$isDirectAccessToPrivateRoute = preg_match('/^_/', $uri);
|
|
28
|
+
|
|
29
|
+
if ($isDirectAccessToPrivateRoute) {
|
|
30
|
+
return ['path' => $includePath];
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
if ($uri) {
|
|
34
|
+
$groupFolder = findGroupFolder($uri);
|
|
35
|
+
if ($groupFolder) {
|
|
36
|
+
$path = $baseDir .= $groupFolder;
|
|
37
|
+
if (file_exists($path)) {
|
|
38
|
+
$includePath = $path;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
if (substr($uri, -4) == '.php') {
|
|
29
43
|
$path = $baseDir . '/' . $uri;
|
|
30
44
|
if (file_exists($path)) {
|
|
31
45
|
$includePath = $path;
|
|
32
46
|
}
|
|
33
47
|
} else {
|
|
34
|
-
$path = $baseDir .
|
|
48
|
+
$path = $baseDir . "/$uri/index.php";
|
|
35
49
|
if (file_exists($path)) {
|
|
36
50
|
$includePath = $path;
|
|
37
51
|
}
|
|
@@ -43,6 +57,111 @@ function determineContentToInclude()
|
|
|
43
57
|
return ['path' => $includePath];
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
function checkForDuplicateRoutes()
|
|
61
|
+
{
|
|
62
|
+
$routes = json_decode(file_get_contents(SETTINGS_PATH . "/files_list.json"), true);
|
|
63
|
+
|
|
64
|
+
$normalizedRoutesMap = [];
|
|
65
|
+
foreach ($routes as $route) {
|
|
66
|
+
$routeWithoutGroups = preg_replace('/\(.*?\)/', '', $route);
|
|
67
|
+
$routeTrimmed = ltrim($routeWithoutGroups, '.\\/');
|
|
68
|
+
$routeNormalized = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $routeTrimmed);
|
|
69
|
+
$normalizedRoutesMap[$routeNormalized][] = $route;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
$errorMessages = [];
|
|
73
|
+
foreach ($normalizedRoutesMap as $normalizedRoute => $originalRoutes) {
|
|
74
|
+
if (count($originalRoutes) > 1 && strpos($normalizedRoute, DIRECTORY_SEPARATOR) !== false) {
|
|
75
|
+
$errorMessages[] = "Duplicate route found after normalization: " . $normalizedRoute;
|
|
76
|
+
foreach ($originalRoutes as $originalRoute) {
|
|
77
|
+
$errorMessages[] = "- Grouped original route: " . $originalRoute;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!empty($errorMessages)) {
|
|
83
|
+
$errorMessageString = implode("<br>", $errorMessages);
|
|
84
|
+
throw new Exception($errorMessageString);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function writeRoutes()
|
|
89
|
+
{
|
|
90
|
+
$directory = './';
|
|
91
|
+
|
|
92
|
+
if (is_dir($directory)) {
|
|
93
|
+
$filesList = [];
|
|
94
|
+
|
|
95
|
+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
|
96
|
+
|
|
97
|
+
foreach ($iterator as $file) {
|
|
98
|
+
if ($file->isFile()) {
|
|
99
|
+
$filesList[] = $file->getPathname();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
$jsonData = json_encode($filesList, JSON_PRETTY_PRINT);
|
|
104
|
+
$jsonFileName = SETTINGS_PATH . '/files_list.json';
|
|
105
|
+
@file_put_contents($jsonFileName, $jsonData);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function findGroupFolder($uri): string
|
|
110
|
+
{
|
|
111
|
+
$uriSegments = explode('/', $uri);
|
|
112
|
+
$constructedPath = '';
|
|
113
|
+
$groupFolder = '';
|
|
114
|
+
$finalMatch = '';
|
|
115
|
+
|
|
116
|
+
foreach ($uriSegments as $segment) {
|
|
117
|
+
if (!empty($segment)) {
|
|
118
|
+
if (isGroupIdentifier($segment)) {
|
|
119
|
+
return $segment;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
$constructedPath .= (empty($constructedPath) ? '' : '/') . $segment;
|
|
123
|
+
$matchedGroupFolder = matchGroupFolder($constructedPath);
|
|
124
|
+
if ($matchedGroupFolder) {
|
|
125
|
+
$groupFolder = $matchedGroupFolder;
|
|
126
|
+
$finalMatch = $groupFolder;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ($finalMatch) {
|
|
132
|
+
return $finalMatch;
|
|
133
|
+
} else {
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isGroupIdentifier($segment): bool
|
|
139
|
+
{
|
|
140
|
+
return preg_match('/^\(.*\)$/', $segment);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function matchGroupFolder($constructedPath): ?string
|
|
144
|
+
{
|
|
145
|
+
$routes = json_decode(file_get_contents(SETTINGS_PATH . "/files_list.json"), true);
|
|
146
|
+
$bestMatch = null;
|
|
147
|
+
|
|
148
|
+
foreach ($routes as $route) {
|
|
149
|
+
$normalizedRoute = trim(str_replace('\\', '/', $route), '.');
|
|
150
|
+
$cleanedRoute = preg_replace('/\/\([^)]+\)/', '', $normalizedRoute);
|
|
151
|
+
if (stripos($cleanedRoute, $constructedPath) !== false) {
|
|
152
|
+
if ($bestMatch === null || strlen($cleanedRoute) < strlen($bestMatch)) {
|
|
153
|
+
$bestMatch = $normalizedRoute;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if ($bestMatch !== null) {
|
|
159
|
+
return $bestMatch;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
46
165
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
|
47
166
|
$domainName = $_SERVER['HTTP_HOST'];
|
|
48
167
|
$scriptPath = dirname($_SERVER['SCRIPT_NAME']);
|
|
@@ -78,6 +197,8 @@ register_shutdown_function(function () use (&$content) {
|
|
|
78
197
|
|
|
79
198
|
try {
|
|
80
199
|
$result = determineContentToInclude();
|
|
200
|
+
writeRoutes();
|
|
201
|
+
checkForDuplicateRoutes();
|
|
81
202
|
$contentToInclude = $result['path'] ?? '';
|
|
82
203
|
|
|
83
204
|
if (!empty($contentToInclude)) {
|
|
@@ -7,8 +7,8 @@ const serverScriptPath = path.join(
|
|
|
7
7
|
__dirname,
|
|
8
8
|
"..",
|
|
9
9
|
"src",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"Lib",
|
|
11
|
+
"Websocket",
|
|
12
12
|
"server.php"
|
|
13
13
|
);
|
|
14
14
|
|
|
@@ -46,7 +46,7 @@ restartServer();
|
|
|
46
46
|
// Watch for changes and restart the server
|
|
47
47
|
const chokidar = require("chokidar");
|
|
48
48
|
chokidar
|
|
49
|
-
.watch(path.join(__dirname, "..", "src", "
|
|
49
|
+
.watch(path.join(__dirname, "..", "src", "Lib", "Websocket", "**", "*"))
|
|
50
50
|
.on("change", (event, path) => {
|
|
51
51
|
console.log(`${event}: ${path}`);
|
|
52
52
|
restartServer();
|
|
@@ -17,7 +17,7 @@ class ConnectionManager implements MessageComponentInterface
|
|
|
17
17
|
public function onOpen(ConnectionInterface $conn)
|
|
18
18
|
{
|
|
19
19
|
$this->clients->attach($conn);
|
|
20
|
-
echo "New connection! ({$conn->resourceId})
|
|
20
|
+
echo "New connection! ({$conn->resourceId})";
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public function onMessage(ConnectionInterface $from, $msg)
|
|
@@ -28,12 +28,12 @@ class ConnectionManager implements MessageComponentInterface
|
|
|
28
28
|
public function onClose(ConnectionInterface $conn)
|
|
29
29
|
{
|
|
30
30
|
$this->clients->detach($conn);
|
|
31
|
-
echo "Connection {$conn->resourceId} has disconnected
|
|
31
|
+
echo "Connection {$conn->resourceId} has disconnected";
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
public function onError(ConnectionInterface $conn, \Exception $e)
|
|
35
35
|
{
|
|
36
|
-
echo "An error has occurred: {$e->getMessage()}
|
|
36
|
+
echo "An error has occurred: {$e->getMessage()}";
|
|
37
37
|
$conn->close();
|
|
38
38
|
}
|
|
39
39
|
}
|