create-prisma-php-app 1.26.503 → 1.26.505
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 +85 -24
- package/dist/index.js +1 -1
- package/dist/settings/auto-swagger-docs.ts +409 -214
- package/dist/settings/bs-config.ts +2 -2
- package/dist/settings/prisma-schema-config.json +13 -4
- package/dist/settings/project-name.ts +10 -7
- package/dist/settings/swagger-config.ts +5 -4
- package/dist/src/Lib/AI/ChatGPTClient.php +2 -0
- package/dist/src/Lib/Auth/Auth.php +5 -3
- package/dist/src/Lib/Auth/AuthConfig.php +2 -0
- package/dist/src/Lib/FileManager/UploadFile.php +2 -0
- package/dist/src/Lib/Headers/Boom.php +2 -0
- package/dist/src/Lib/MainLayout.php +2 -0
- package/dist/src/Lib/Middleware/AuthMiddleware.php +2 -0
- package/dist/src/Lib/PHPMailer/Mailer.php +2 -0
- package/dist/src/Lib/PrismaPHPSettings.php +71 -15
- package/dist/src/Lib/Request.php +79 -33
- package/dist/src/Lib/StateManager.php +2 -0
- package/dist/src/Lib/Validator.php +2 -0
- package/dist/src/Lib/Websocket/ConnectionManager.php +2 -0
- package/dist/src/Lib/Websocket/server.php +2 -0
- package/dist/src/app/js/index.js +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { createProxyMiddleware } from "http-proxy-middleware";
|
|
|
2
2
|
import { writeFileSync } from "fs";
|
|
3
3
|
import chokidar from "chokidar";
|
|
4
4
|
import browserSync, { BrowserSyncInstance } from "browser-sync";
|
|
5
|
-
import
|
|
5
|
+
import prismaPhpConfigJson from "../prisma-php.json";
|
|
6
6
|
import { generateFileListJson } from "./files-list.js";
|
|
7
7
|
import { join } from "path";
|
|
8
8
|
import { getFileMeta } from "./utils.js";
|
|
@@ -43,7 +43,7 @@ bs.init(
|
|
|
43
43
|
next();
|
|
44
44
|
},
|
|
45
45
|
createProxyMiddleware({
|
|
46
|
-
target:
|
|
46
|
+
target: prismaPhpConfigJson.bsTarget,
|
|
47
47
|
changeOrigin: true,
|
|
48
48
|
pathRewrite: {},
|
|
49
49
|
}),
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"swaggerDocsDir": "src/app/swagger-docs/apis",
|
|
3
|
-
"skipDefaultName": [
|
|
4
|
-
|
|
3
|
+
"skipDefaultName": [
|
|
4
|
+
"autoincrement",
|
|
5
|
+
"cuid",
|
|
6
|
+
"uuid",
|
|
7
|
+
"now"
|
|
8
|
+
],
|
|
9
|
+
"skipByPropertyValue": {
|
|
10
|
+
"isUpdatedAt": true
|
|
11
|
+
},
|
|
12
|
+
"skipFields": [],
|
|
13
|
+
"generateSwaggerDocsOnly": true,
|
|
5
14
|
"generateEndpoints": false,
|
|
6
|
-
"generatePhpClasses":
|
|
7
|
-
}
|
|
15
|
+
"generatePhpClasses": false
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, unlink, writeFile } from "fs";
|
|
2
2
|
import { join, basename, dirname, normalize, sep } from "path";
|
|
3
|
-
import
|
|
3
|
+
import prismaPhpConfigJson from "../prisma-php.json";
|
|
4
4
|
import { getFileMeta } from "./utils.js";
|
|
5
5
|
|
|
6
6
|
const { __dirname } = getFileMeta();
|
|
@@ -15,20 +15,23 @@ function updateProjectNameInConfig(
|
|
|
15
15
|
const filePathDir = dirname(filePath);
|
|
16
16
|
|
|
17
17
|
// Update the projectName directly in the imported config
|
|
18
|
-
|
|
18
|
+
prismaPhpConfigJson.projectName = newProjectName;
|
|
19
19
|
|
|
20
20
|
// Update other paths
|
|
21
|
-
|
|
21
|
+
prismaPhpConfigJson.projectRootPath = filePathDir;
|
|
22
22
|
|
|
23
|
-
const targetPath = getTargetPath(
|
|
23
|
+
const targetPath = getTargetPath(
|
|
24
|
+
filePathDir,
|
|
25
|
+
prismaPhpConfigJson.phpEnvironment
|
|
26
|
+
);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
prismaPhpConfigJson.bsTarget = `http://localhost${targetPath}`;
|
|
29
|
+
prismaPhpConfigJson.bsPathRewrite["^/"] = targetPath;
|
|
27
30
|
|
|
28
31
|
// Save the updated config back to the JSON file
|
|
29
32
|
writeFile(
|
|
30
33
|
filePath,
|
|
31
|
-
JSON.stringify(
|
|
34
|
+
JSON.stringify(prismaPhpConfigJson, null, 2),
|
|
32
35
|
"utf8",
|
|
33
36
|
(err) => {
|
|
34
37
|
if (err) {
|
|
@@ -3,7 +3,8 @@ import { writeFileSync } from "fs";
|
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { getFileMeta } from "./utils.js";
|
|
6
|
-
import
|
|
6
|
+
import bsConfigJson from "./bs-config.json";
|
|
7
|
+
import prismaPhpConfigJson from "../prisma-php.json";
|
|
7
8
|
|
|
8
9
|
const { __dirname } = getFileMeta();
|
|
9
10
|
|
|
@@ -23,7 +24,7 @@ export async function swaggerConfig(): Promise<void> {
|
|
|
23
24
|
},
|
|
24
25
|
servers: [
|
|
25
26
|
{
|
|
26
|
-
url:
|
|
27
|
+
url: bsConfigJson.local, // For Development
|
|
27
28
|
description: "Development Server",
|
|
28
29
|
},
|
|
29
30
|
{
|
|
@@ -65,5 +66,5 @@ export async function swaggerConfig(): Promise<void> {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
swaggerConfig();
|
|
69
|
+
if (prismaPhpConfigJson.swaggerDocs && !prismaPhpConfigJson.prisma)
|
|
70
|
+
swaggerConfig();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
3
5
|
namespace Lib\Auth;
|
|
4
6
|
|
|
5
7
|
use Firebase\JWT\JWT;
|
|
@@ -13,10 +15,10 @@ use Lib\Request;
|
|
|
13
15
|
|
|
14
16
|
class Auth
|
|
15
17
|
{
|
|
16
|
-
public const PAYLOAD_NAME = '
|
|
18
|
+
public const PAYLOAD_NAME = 'payload_name_8639D';
|
|
17
19
|
public const ROLE_NAME = '';
|
|
18
|
-
public const PAYLOAD_SESSION_KEY = '
|
|
19
|
-
public const COOKIE_NAME = '
|
|
20
|
+
public const PAYLOAD_SESSION_KEY = 'payload_session_key_2183A';
|
|
21
|
+
public const COOKIE_NAME = 'cookie_name_D36E5';
|
|
20
22
|
|
|
21
23
|
private static ?Auth $instance = null;
|
|
22
24
|
private const PPHPAUTH = 'pphpauth';
|
|
@@ -1,24 +1,72 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
3
5
|
namespace Lib;
|
|
4
6
|
|
|
7
|
+
class BSPathRewrite
|
|
8
|
+
{
|
|
9
|
+
public string $pattern;
|
|
10
|
+
public string $replacement;
|
|
11
|
+
|
|
12
|
+
public function __construct(array $data)
|
|
13
|
+
{
|
|
14
|
+
$this->pattern = $data['pattern'] ?? '';
|
|
15
|
+
$this->replacement = $data['replacement'] ?? '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class PrismaSettings
|
|
20
|
+
{
|
|
21
|
+
public string $projectName;
|
|
22
|
+
public string $projectRootPath;
|
|
23
|
+
public string $phpEnvironment;
|
|
24
|
+
public string $phpRootPathExe;
|
|
25
|
+
public string $phpGenerateClassPath;
|
|
26
|
+
public string $bsTarget;
|
|
27
|
+
public BSPathRewrite $bsPathRewrite;
|
|
28
|
+
public bool $backendOnly;
|
|
29
|
+
public bool $swaggerDocs;
|
|
30
|
+
public bool $tailwindcss;
|
|
31
|
+
public bool $websocket;
|
|
32
|
+
public bool $prisma;
|
|
33
|
+
public bool $docker;
|
|
34
|
+
public string $version;
|
|
35
|
+
public array $excludeFiles;
|
|
36
|
+
|
|
37
|
+
public function __construct(array $data)
|
|
38
|
+
{
|
|
39
|
+
$this->projectName = $data['projectName'] ?? '';
|
|
40
|
+
$this->projectRootPath = $data['projectRootPath'] ?? '';
|
|
41
|
+
$this->phpEnvironment = $data['phpEnvironment'] ?? '';
|
|
42
|
+
$this->phpRootPathExe = $data['phpRootPathExe'] ?? '';
|
|
43
|
+
$this->phpGenerateClassPath = $data['phpGenerateClassPath'] ?? '';
|
|
44
|
+
$this->bsTarget = $data['bsTarget'] ?? '';
|
|
45
|
+
$this->bsPathRewrite = new BSPathRewrite($data['bsPathRewrite'] ?? []);
|
|
46
|
+
$this->backendOnly = $data['backendOnly'] ?? false;
|
|
47
|
+
$this->swaggerDocs = $data['swaggerDocs'] ?? true;
|
|
48
|
+
$this->tailwindcss = $data['tailwindcss'] ?? true;
|
|
49
|
+
$this->websocket = $data['websocket'] ?? true;
|
|
50
|
+
$this->prisma = $data['prisma'] ?? true;
|
|
51
|
+
$this->docker = $data['docker'] ?? false;
|
|
52
|
+
$this->version = $data['version'] ?? '';
|
|
53
|
+
$this->excludeFiles = $data['excludeFiles'] ?? [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
5
57
|
class PrismaPHPSettings
|
|
6
58
|
{
|
|
7
59
|
/**
|
|
8
60
|
* The settings from the prisma-php.json file.
|
|
9
61
|
*
|
|
10
|
-
* @var
|
|
11
|
-
* @access public
|
|
12
|
-
* @static
|
|
62
|
+
* @var PrismaSettings
|
|
13
63
|
*/
|
|
14
|
-
public static
|
|
64
|
+
public static PrismaSettings $option;
|
|
15
65
|
|
|
16
66
|
/**
|
|
17
67
|
* The list of route files from the files-list.json file.
|
|
18
68
|
*
|
|
19
69
|
* @var array
|
|
20
|
-
* @access public
|
|
21
|
-
* @static
|
|
22
70
|
*/
|
|
23
71
|
public static array $routeFiles = [];
|
|
24
72
|
|
|
@@ -28,20 +76,28 @@ class PrismaPHPSettings
|
|
|
28
76
|
self::$routeFiles = self::getRoutesFileList();
|
|
29
77
|
}
|
|
30
78
|
|
|
31
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Get Prisma settings from the JSON file.
|
|
81
|
+
*
|
|
82
|
+
* @return PrismaSettings
|
|
83
|
+
* @throws Exception if the JSON file cannot be decoded.
|
|
84
|
+
*/
|
|
85
|
+
private static function getPrismaSettings(): PrismaSettings
|
|
32
86
|
{
|
|
33
87
|
$prismaPHPSettingsJson = DOCUMENT_PATH . '/prisma-php.json';
|
|
34
88
|
|
|
35
|
-
if (file_exists($prismaPHPSettingsJson)) {
|
|
36
|
-
|
|
37
|
-
|
|
89
|
+
if (!file_exists($prismaPHPSettingsJson)) {
|
|
90
|
+
throw new \Exception("Settings file not found: $prismaPHPSettingsJson");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
$jsonContent = file_get_contents($prismaPHPSettingsJson);
|
|
94
|
+
$decodedJson = json_decode($jsonContent, true);
|
|
38
95
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} else {
|
|
42
|
-
return new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
|
|
43
|
-
}
|
|
96
|
+
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
97
|
+
throw new \Exception("Failed to decode JSON: " . json_last_error_msg());
|
|
44
98
|
}
|
|
99
|
+
|
|
100
|
+
return new PrismaSettings($decodedJson);
|
|
45
101
|
}
|
|
46
102
|
|
|
47
103
|
private static function getRoutesFileList(): array
|
package/dist/src/Lib/Request.php
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
3
5
|
namespace Lib;
|
|
4
6
|
|
|
7
|
+
use Lib\Headers\Boom;
|
|
8
|
+
|
|
5
9
|
class Request
|
|
6
10
|
{
|
|
7
11
|
/**
|
|
@@ -160,6 +164,11 @@ class Request
|
|
|
160
164
|
*/
|
|
161
165
|
public static bool $isXFileRequest = false;
|
|
162
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @var string $requestedWith Holds the value of the X-Requested-With header.
|
|
169
|
+
*/
|
|
170
|
+
public static string $requestedWith = '';
|
|
171
|
+
|
|
163
172
|
/**
|
|
164
173
|
* Initialize the request by setting all static properties.
|
|
165
174
|
*/
|
|
@@ -173,6 +182,7 @@ class Request
|
|
|
173
182
|
self::$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
|
174
183
|
self::$domainName = $_SERVER['HTTP_HOST'] ?? '';
|
|
175
184
|
self::$scriptName = dirname($_SERVER['SCRIPT_NAME']);
|
|
185
|
+
self::$requestedWith = $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '';
|
|
176
186
|
|
|
177
187
|
self::$isGet = self::$method === 'GET';
|
|
178
188
|
self::$isPost = self::$method === 'POST';
|
|
@@ -191,12 +201,45 @@ class Request
|
|
|
191
201
|
}
|
|
192
202
|
|
|
193
203
|
/**
|
|
194
|
-
*
|
|
204
|
+
* Determines if the current request is an AJAX request.
|
|
205
|
+
*
|
|
206
|
+
* @return bool True if the request is an AJAX request, false otherwise.
|
|
195
207
|
*/
|
|
196
208
|
private static function isAjaxRequest(): bool
|
|
197
209
|
{
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
// Check for standard AJAX header
|
|
211
|
+
if (
|
|
212
|
+
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
|
213
|
+
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'
|
|
214
|
+
) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Check for common AJAX content types
|
|
219
|
+
if (!empty($_SERVER['CONTENT_TYPE'])) {
|
|
220
|
+
$ajaxContentTypes = [
|
|
221
|
+
'application/json',
|
|
222
|
+
'application/x-www-form-urlencoded',
|
|
223
|
+
'multipart/form-data',
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
foreach ($ajaxContentTypes as $contentType) {
|
|
227
|
+
if (stripos($_SERVER['CONTENT_TYPE'], $contentType) !== false) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Check for common AJAX request methods
|
|
234
|
+
$ajaxMethods = ['POST', 'PUT', 'PATCH', 'DELETE'];
|
|
235
|
+
if (
|
|
236
|
+
!empty($_SERVER['REQUEST_METHOD']) &&
|
|
237
|
+
in_array(strtoupper($_SERVER['REQUEST_METHOD']), $ajaxMethods, true)
|
|
238
|
+
) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return false;
|
|
200
243
|
}
|
|
201
244
|
|
|
202
245
|
/**
|
|
@@ -217,8 +260,8 @@ class Request
|
|
|
217
260
|
{
|
|
218
261
|
$serverFetchSite = $_SERVER['HTTP_SEC_FETCH_SITE'] ?? '';
|
|
219
262
|
if (isset($serverFetchSite) && $serverFetchSite === 'same-origin') {
|
|
220
|
-
$headers = getallheaders();
|
|
221
|
-
return isset($headers['http_pphp_x_file_request']) &&
|
|
263
|
+
$headers = array_change_key_case(getallheaders(), CASE_LOWER);
|
|
264
|
+
return isset($headers['http_pphp_x_file_request']) && $headers['http_pphp_x_file_request'] === 'true';
|
|
222
265
|
}
|
|
223
266
|
|
|
224
267
|
return false;
|
|
@@ -226,37 +269,42 @@ class Request
|
|
|
226
269
|
|
|
227
270
|
/**
|
|
228
271
|
* Get the request parameters.
|
|
272
|
+
*
|
|
273
|
+
* @return \ArrayObject The request parameters as an \ArrayObject with properties.
|
|
229
274
|
*/
|
|
230
275
|
private static function getParams(): \ArrayObject
|
|
231
276
|
{
|
|
232
277
|
$params = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
|
|
233
278
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
279
|
+
switch (self::$method) {
|
|
280
|
+
case 'GET':
|
|
281
|
+
$params = new \ArrayObject($_GET, \ArrayObject::ARRAY_AS_PROPS);
|
|
282
|
+
break;
|
|
283
|
+
default:
|
|
284
|
+
// Handle JSON input with different variations (e.g., application/json, application/ld+json, etc.)
|
|
285
|
+
if (preg_match('#^application/(|\S+\+)json($|[ ;])#', self::$contentType)) {
|
|
286
|
+
$jsonInput = file_get_contents('php://input');
|
|
287
|
+
if ($jsonInput !== false && !empty($jsonInput)) {
|
|
288
|
+
self::$data = json_decode($jsonInput, true);
|
|
289
|
+
if (json_last_error() === JSON_ERROR_NONE) {
|
|
290
|
+
$params = new \ArrayObject(self::$data, \ArrayObject::ARRAY_AS_PROPS);
|
|
291
|
+
} else {
|
|
292
|
+
Boom::badRequest('Invalid JSON body')->toResponse();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
248
295
|
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
296
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
297
|
+
// Handle URL-encoded input
|
|
298
|
+
if (stripos(self::$contentType, 'application/x-www-form-urlencoded') !== false) {
|
|
299
|
+
$rawInput = file_get_contents('php://input');
|
|
300
|
+
if ($rawInput !== false && !empty($rawInput)) {
|
|
301
|
+
parse_str($rawInput, $parsedParams);
|
|
302
|
+
$params = new \ArrayObject($parsedParams, \ArrayObject::ARRAY_AS_PROPS);
|
|
303
|
+
} else {
|
|
304
|
+
$params = new \ArrayObject($_POST, \ArrayObject::ARRAY_AS_PROPS);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
260
308
|
}
|
|
261
309
|
|
|
262
310
|
return $params;
|
|
@@ -265,7 +313,7 @@ class Request
|
|
|
265
313
|
/**
|
|
266
314
|
* Get the protocol of the request.
|
|
267
315
|
*/
|
|
268
|
-
|
|
316
|
+
private static function getProtocol(): string
|
|
269
317
|
{
|
|
270
318
|
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
|
|
271
319
|
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
|
|
@@ -304,9 +352,7 @@ class Request
|
|
|
304
352
|
public static function checkAllowedMethods(): void
|
|
305
353
|
{
|
|
306
354
|
if (!in_array(self::$method, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'])) {
|
|
307
|
-
|
|
308
|
-
echo json_encode(['error' => 'Method not allowed']);
|
|
309
|
-
exit;
|
|
355
|
+
Boom::methodNotAllowed()->toResponse();
|
|
310
356
|
}
|
|
311
357
|
}
|
|
312
358
|
|