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.
@@ -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 prismaPhpConfig from "../prisma-php.json";
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: prismaPhpConfig.bsTarget,
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": ["autoincrement", "cuid", "uuid", "now"],
4
- "skipFields": ["updatedAt"],
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": true
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 prismaPhpConfig from "../prisma-php.json";
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
- prismaPhpConfig.projectName = newProjectName;
18
+ prismaPhpConfigJson.projectName = newProjectName;
19
19
 
20
20
  // Update other paths
21
- prismaPhpConfig.projectRootPath = filePathDir;
21
+ prismaPhpConfigJson.projectRootPath = filePathDir;
22
22
 
23
- const targetPath = getTargetPath(filePathDir, prismaPhpConfig.phpEnvironment);
23
+ const targetPath = getTargetPath(
24
+ filePathDir,
25
+ prismaPhpConfigJson.phpEnvironment
26
+ );
24
27
 
25
- prismaPhpConfig.bsTarget = `http://localhost${targetPath}`;
26
- prismaPhpConfig.bsPathRewrite["^/"] = targetPath;
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(prismaPhpConfig, null, 2),
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 bsConnectionInfo from "./bs-config.json";
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: bsConnectionInfo.local, // For Development
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
- // Call the function to generate the Swagger JSON
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\AI;
4
6
 
5
7
  use GuzzleHttp\Client;
@@ -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 = 'role';
18
+ public const PAYLOAD_NAME = 'payload_name_8639D';
17
19
  public const ROLE_NAME = '';
18
- public const PAYLOAD_SESSION_KEY = 'payload_2183A';
19
- public const COOKIE_NAME = 'pphp_aut_token_D36E5';
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,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\Auth;
4
6
 
5
7
  enum AuthRole: string
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\FileManager;
4
6
 
5
7
  class UploadFile
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\Headers;
4
6
 
5
7
  /**
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib;
4
6
 
5
7
  class MainLayout
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\Middleware;
4
6
 
5
7
  use Lib\Auth\Auth;
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\PHPMailer;
4
6
 
5
7
  use PHPMailer\PHPMailer\PHPMailer;
@@ -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 \stdClass
11
- * @access public
12
- * @static
62
+ * @var PrismaSettings
13
63
  */
14
- public static \ArrayObject $option;
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
- private static function getPrismaSettings(): \ArrayObject
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
- $jsonContent = file_get_contents($prismaPHPSettingsJson);
37
- $decodedJson = json_decode($jsonContent, true);
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
- if (json_last_error() === JSON_ERROR_NONE) {
40
- return new \ArrayObject($decodedJson, \ArrayObject::ARRAY_AS_PROPS);
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
@@ -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
- * Checks if the request is an AJAX request.
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
- return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
199
- || in_array(strtoupper(self::$method), ['POST', 'PUT', 'PATCH', 'DELETE']);
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']) && strtolower($headers['http_pphp_x_file_request']) === 'true';
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
- if (self::$method === 'GET') {
235
- $params = new \ArrayObject($_GET, \ArrayObject::ARRAY_AS_PROPS);
236
- }
237
-
238
- if (stripos(self::$contentType, 'application/json') !== false) {
239
- $jsonInput = file_get_contents('php://input');
240
- if (!empty($jsonInput)) {
241
- self::$data = json_decode($jsonInput, true);
242
- if (json_last_error() === JSON_ERROR_NONE) {
243
- $params = new \ArrayObject(self::$data, \ArrayObject::ARRAY_AS_PROPS);
244
- } else {
245
- header('HTTP/1.1 400 Bad Request');
246
- echo json_encode(['error' => 'Invalid JSON body']);
247
- exit;
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
- if (stripos(self::$contentType, 'application/x-www-form-urlencoded') !== false) {
253
- if (in_array(self::$method, ['POST', 'PUT', 'PATCH', 'DELETE'])) {
254
- $rawInput = file_get_contents('php://input');
255
- parse_str($rawInput, $parsedParams);
256
- $params = new \ArrayObject($parsedParams, \ArrayObject::ARRAY_AS_PROPS);
257
- } else {
258
- $params = new \ArrayObject($_POST, \ArrayObject::ARRAY_AS_PROPS);
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
- public static function getProtocol(): string
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
- header('HTTP/1.1 405 Method Not Allowed');
308
- echo json_encode(['error' => 'Method not allowed']);
309
- exit;
355
+ Boom::methodNotAllowed()->toResponse();
310
356
  }
311
357
  }
312
358
 
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib;
4
6
 
5
7
  use Lib\Request;
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib;
4
6
 
5
7
  use HTMLPurifier;
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  namespace Lib\Websocket;
4
6
 
5
7
  use Ratchet\MessageComponentInterface;
@@ -1,5 +1,7 @@
1
1
  <?php
2
2
 
3
+ declare(strict_types=1);
4
+
3
5
  require __DIR__ . '/../../../vendor/autoload.php';
4
6
 
5
7
  use Ratchet\Server\IoServer;