create-prisma-php-app 1.20.516 → 1.20.518

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.
@@ -386,15 +386,41 @@ function setupErrorHandling(&$content)
386
386
  ob_start();
387
387
  require_once SETTINGS_PATH . '/public-functions.php';
388
388
  require_once SETTINGS_PATH . '/request-methods.php';
389
- $metadataFile = APP_PATH . '/metadata.php';
390
- $_metadataArray = file_exists($metadataFile) ? require_once $metadataFile : [];
389
+ $_metadataFile = APP_PATH . '/metadata.php';
390
+ $_metadataArray = file_exists($_metadataFile) ? require_once $_metadataFile : [];
391
391
  $_filesListRoutes = [];
392
- $metadata = "";
392
+ /**
393
+ * @var array $metadata Metadata information
394
+ */
395
+ $metadata = [];
396
+ /**
397
+ * @var string $uri The URI of the current request
398
+ */
393
399
  $uri = "";
400
+ /**
401
+ * @var string $pathname The pathname of the current request
402
+ */
394
403
  $pathname = "";
404
+ /**
405
+ * @var array $dynamicRouteParams The dynamic route parameters
406
+ */
395
407
  $dynamicRouteParams = [];
408
+ /**
409
+ * @var string $content The content to be included in the main layout file
410
+ */
396
411
  $content = "";
412
+ /**
413
+ * @var string $childContent The child content to be included in the layout file
414
+ */
397
415
  $childContent = "";
416
+ /**
417
+ * @var array $mainLayoutHead The head content to be included in the main layout file
418
+ */
419
+ $mainLayoutHead = [];
420
+ /**
421
+ * @var array $mainLayoutFooter The footer content to be included in the main layout file
422
+ */
423
+ $mainLayoutFooter = [];
398
424
 
399
425
  function containsChildContent($filePath)
400
426
  {
@@ -639,7 +665,7 @@ try {
639
665
  exit;
640
666
  }
641
667
 
642
- $metadata = $_metadataArray[$uri] ?? ($_metadataArray['default'] ?? null);
668
+ $metadata = $_metadataArray[$uri] ?? ($_metadataArray['default'] ?? []);
643
669
  $_parentLayoutPath = APP_PATH . '/layout.php';
644
670
  $_isParentLayout = !empty($_layoutsToInclude) && strpos($_layoutsToInclude[0], 'src/app/layout.php') !== false;
645
671
 
package/dist/index.js CHANGED
@@ -351,9 +351,10 @@ function modifyLayoutPHP(baseDir, answer) {
351
351
  // Insert before the closing </head> tag
352
352
  indexContent = indexContent.replace(
353
353
  "</head>",
354
- `${tailwindLink}\n <!-- Dynamic Head -->\n
355
- <?php echo implode("\n", $mainLayoutHead); ?></head>`
354
+ `${tailwindLink}\n <!-- Dynamic Head -->
355
+ <?php echo implode("\\n", $mainLayoutHead); ?></head>`
356
356
  );
357
+ console.log("🚀 ~ modifyLayoutPHP ~ indexContent:", indexContent);
357
358
  fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
358
359
  console.log(
359
360
  chalk.green(
@@ -1,10 +1,30 @@
1
1
  <?php
2
2
 
3
- // Absolute path
3
+ /**
4
+ * @var string SETTINGS_PATH - The absolute path to the settings directory
5
+ */
4
6
  define("SETTINGS_PATH", dirname(__FILE__));
7
+ /**
8
+ * @var string PUBLIC_PATH - The absolute path to the public directory
9
+ */
5
10
  define("PUBLIC_PATH", dirname(SETTINGS_PATH) . "/public");
11
+ /**
12
+ * @var string PRISMA_LIB_PATH - The absolute path to the Prisma library directory
13
+ */
6
14
  define("PRISMA_LIB_PATH", dirname(SETTINGS_PATH) . "/src/Lib/Prisma");
15
+ /**
16
+ * @var string SRC_PATH - The absolute path to the src directory
17
+ */
7
18
  define("SRC_PATH", dirname(SETTINGS_PATH) . "/src");
19
+ /**
20
+ * @var string APP_PATH - The absolute path to the app directory
21
+ */
8
22
  define("APP_PATH", dirname(SETTINGS_PATH) . "/src/app");
23
+ /**
24
+ * @var string LIB_PATH - The absolute path to the layout directory
25
+ */
9
26
  define("LIB_PATH", dirname(SETTINGS_PATH) . "/src/Lib");
27
+ /**
28
+ * @var string DOCUMENT_PATH - The absolute path to the layout directory
29
+ */
10
30
  define("DOCUMENT_PATH", dirname(SETTINGS_PATH));
@@ -1,5 +1,8 @@
1
1
  <?php
2
2
 
3
+ /**
4
+ * @var string $requestMethod - The request method.
5
+ */
3
6
  $requestMethod = $_SERVER['REQUEST_METHOD'];
4
7
 
5
8
  if ($requestMethod == 'OPTIONS') {
@@ -7,6 +10,9 @@ if ($requestMethod == 'OPTIONS') {
7
10
  exit;
8
11
  }
9
12
 
13
+ /**
14
+ * @var array $allowedMethods - The allowed request methods.
15
+ */
10
16
  $allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
11
17
 
12
18
  if (!in_array($requestMethod, $allowedMethods)) {
@@ -15,27 +21,83 @@ if (!in_array($requestMethod, $allowedMethods)) {
15
21
  exit;
16
22
  }
17
23
 
24
+ /**
25
+ * @var bool $isGet - True if the request method is GET, false otherwise.
26
+ */
18
27
  $isGet = $requestMethod === 'GET';
28
+ /**
29
+ * @var bool $isPost - True if the request method is POST, false otherwise.
30
+ */
19
31
  $isPost = $requestMethod === 'POST';
32
+ /**
33
+ * @var bool $isPut - True if the request method is PUT, false otherwise.
34
+ */
20
35
  $isPut = $requestMethod === 'PUT';
36
+ /**
37
+ * @var bool $isDelete - True if the request method is DELETE, false otherwise.
38
+ */
21
39
  $isDelete = $requestMethod === 'DELETE';
40
+ /**
41
+ * @var bool $isPatch - True if the request method is PATCH, false otherwise.
42
+ */
22
43
  $isPatch = $requestMethod === 'PATCH';
44
+ /**
45
+ * @var bool $isHead - True if the request method is HEAD, false otherwise.
46
+ */
23
47
  $isHead = $requestMethod === 'HEAD';
48
+ /**
49
+ * @var bool $isOptions - True if the request method is OPTIONS, false otherwise.
50
+ */
24
51
  $isOptions = $requestMethod === 'OPTIONS';
52
+ /**
53
+ * @var bool $isAjax - True if the request is an AJAX request, false otherwise.
54
+ */
25
55
  $isAjax = isAjaxRequest();
56
+ /**
57
+ * @var bool $isWire - True if the request is a wire request, false otherwise.
58
+ */
26
59
  $isWire = isWireRequest();
60
+ /**
61
+ * @var bool $isXFilRequest - True if the request is an X-Fil request, false otherwise.
62
+ */
27
63
  $isXFilRequest = isXFilRequest();
64
+ /**
65
+ * @var string $contentType - The content type of the request.
66
+ */
28
67
  $contentType = $_SERVER['CONTENT_TYPE'] ?? '';
68
+ /**
69
+ * @var string $requestedWith - The X-Requested-With header of the request.
70
+ */
29
71
  $requestedWith = $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '';
72
+ /**
73
+ * @var string $protocol - The protocol of the request.
74
+ */
30
75
  $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
31
76
  (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
32
77
  $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
78
+ /**
79
+ * @var string $domainName - The domain name of the request.
80
+ */
33
81
  $domainName = $_SERVER['HTTP_HOST'];
34
- $scriptName = dirname($_SERVER['SCRIPT_NAME']) . '/';
35
- $baseUrl = $protocol . $domainName . rtrim($scriptName, '/') . '/src/app';
36
- $documentUrl = $protocol . $domainName . rtrim($scriptName, '/');
82
+ /**
83
+ * @var string $scriptName - The script name of the request.
84
+ */
85
+ $scriptName = dirname($_SERVER['SCRIPT_NAME']);
86
+ /**
87
+ * @var string $baseUrl - The base URL of the request.
88
+ */
89
+ $baseUrl = $protocol . $domainName . "$scriptName/src/app";
90
+ /**
91
+ * @var string $documentUrl - The document URL of the request.
92
+ */
93
+ $documentUrl = $protocol . $domainName . $scriptName;
94
+ /**
95
+ * @var string $referer - The referer of the request.
96
+ */
37
97
  $referer = $_SERVER['HTTP_REFERER'] ?? 'Unknown';
38
-
98
+ /**
99
+ * @var \ArrayObject $params - The request parameters
100
+ */
39
101
  $params = [];
40
102
 
41
103
  if ($requestMethod == 'GET') {
@@ -1,9 +1,21 @@
1
- import { exec } from "child_process";
1
+ import { exec, spawn } from "child_process";
2
2
  import chalk from "chalk";
3
3
  import { writeFileSync } from "fs";
4
4
  import readline from "readline";
5
5
 
6
- function runCommand(command, options = {}) {
6
+ const BROWSERSYNC_PREFIX = "[Browsersync]";
7
+ const REGEX_PATTERNS = {
8
+ BROWSERSYNC: /^\[Browsersync\]\s*(.+)$/,
9
+ PROXYING: /Proxying/,
10
+ ACCESS_URLS: /Access URLs:/,
11
+ LOCAL_URL: /Local:\s*(http:\/\/.+)/,
12
+ EXTERNAL_URL: /External:\s*(http:\/\/\S+)/,
13
+ UI_URL: /UI:\s*(http:\/\/.+)/,
14
+ UI_EXTERNAL_URL: /UI External:\s*(http:\/\/.+)/,
15
+ WATCHING_FILES: /Watching files/,
16
+ };
17
+
18
+ async function runCommand(command, options = {}) {
7
19
  return new Promise((resolve, reject) => {
8
20
  const process = exec(command, options);
9
21
 
@@ -31,6 +43,8 @@ function runCommand(command, options = {}) {
31
43
  }
32
44
 
33
45
  async function startDev() {
46
+ let browserSync;
47
+ let devProcess;
34
48
  try {
35
49
  // Step 1: Start projectName and wait for it to complete
36
50
  console.log("Starting projectName...");
@@ -39,8 +53,9 @@ async function startDev() {
39
53
 
40
54
  // Step 2: Start browserSync and process its output
41
55
  console.log("Starting browser-sync...");
42
- const browserSync = exec("npm run browserSync");
43
- let formattedLog = {
56
+ browserSync = spawn("npm", ["run", "browserSync"], { shell: true });
57
+
58
+ const formattedLog = {
44
59
  local: "",
45
60
  external: "",
46
61
  ui: "",
@@ -55,44 +70,52 @@ async function startDev() {
55
70
  let browserSyncReady = false;
56
71
 
57
72
  rl.on("line", (line) => {
58
- if (/Proxying/.test(line)) {
59
- console.log(line.trim());
60
- } else if (/Access URLs:/.test(line)) {
61
- console.log(chalk.green("[Browsersync] Access URLs:"));
62
- } else if (/Local:/.test(line)) {
63
- const match = line.match(/Local:\s*(http:\/\/.+)/);
73
+ if (REGEX_PATTERNS.PROXYING.test(line)) {
74
+ const match = line.match(REGEX_PATTERNS.BROWSERSYNC);
75
+ if (match) {
76
+ console.log(`${chalk.blue(BROWSERSYNC_PREFIX)} ${match[1]}`);
77
+ }
78
+ } else if (REGEX_PATTERNS.ACCESS_URLS.test(line)) {
79
+ const match = line.match(REGEX_PATTERNS.BROWSERSYNC);
80
+ if (match) {
81
+ console.log(`${chalk.blue(BROWSERSYNC_PREFIX)} ${match[1]}`);
82
+ }
83
+ } else if (REGEX_PATTERNS.LOCAL_URL.test(line)) {
84
+ const match = line.match(REGEX_PATTERNS.LOCAL_URL);
64
85
  if (match) {
65
86
  const localUrl = match[1];
66
87
  formattedLog.local = localUrl;
67
- console.log(chalk.white("Local: ") + chalk.cyanBright(localUrl));
88
+ console.log(`${chalk.white("Local: ")}${chalk.cyanBright(localUrl)}`);
68
89
  }
69
90
  } else if (/^ {4}External:/.test(line)) {
70
- const match = line.match(/External:\s*(http:\/\/\S+)/);
91
+ const match = line.match(REGEX_PATTERNS.EXTERNAL_URL);
71
92
  if (match) {
72
93
  const externalUrl = match[1];
73
94
  formattedLog.external = externalUrl;
74
95
  console.log(
75
- chalk.white("External: ") + chalk.magentaBright(externalUrl)
96
+ `${chalk.white("External: ")}${chalk.magentaBright(externalUrl)}`
76
97
  );
77
98
  }
78
- } else if (/UI:/.test(line)) {
79
- const match = line.match(/UI:\s*(http:\/\/.+)/);
99
+ } else if (REGEX_PATTERNS.UI_URL.test(line)) {
100
+ const match = line.match(REGEX_PATTERNS.UI_URL);
80
101
  if (match) {
81
102
  const uiUrl = match[1];
82
103
  formattedLog.ui = uiUrl;
83
- console.log(chalk.yellow("UI: ") + chalk.cyanBright(uiUrl));
104
+ console.log(`${chalk.yellow("UI: ")}${chalk.cyanBright(uiUrl)}`);
84
105
  }
85
- } else if (/UI External:/.test(line)) {
86
- const match = line.match(/UI External:\s*(http:\/\/.+)/);
106
+ } else if (REGEX_PATTERNS.UI_EXTERNAL_URL.test(line)) {
107
+ const match = line.match(REGEX_PATTERNS.UI_EXTERNAL_URL);
87
108
  if (match) {
88
109
  const uiExternalUrl = match[1];
89
110
  formattedLog.uiExternal = uiExternalUrl;
90
111
  console.log(
91
- chalk.yellow("UI External: ") + chalk.magentaBright(uiExternalUrl)
112
+ `${chalk.yellow("UI External: ")}${chalk.magentaBright(
113
+ uiExternalUrl
114
+ )}`
92
115
  );
93
116
  }
94
- } else if (/Watching files/.test(line)) {
95
- console.log(`${chalk.blue("[Browsersync]")} Watching files...`);
117
+ } else if (REGEX_PATTERNS.WATCHING_FILES.test(line)) {
118
+ console.log(`${chalk.blue(BROWSERSYNC_PREFIX)} Watching files...`);
96
119
  const outputPath = "./settings/bs-output.json";
97
120
  writeFileSync(
98
121
  outputPath,
@@ -106,27 +129,29 @@ async function startDev() {
106
129
  // Start _dev after browserSync is ready
107
130
  startDevProcess();
108
131
  }
109
- } else if (/Reloading Browsers/.test(line)) {
110
- console.log(`${chalk.blue("[Browsersync]")} Reloading Browsers...`);
132
+ } else if (REGEX_PATTERNS.BROWSERSYNC.test(line)) {
133
+ const match = line.match(REGEX_PATTERNS.BROWSERSYNC);
134
+ if (match) {
135
+ console.log(`${chalk.blue(BROWSERSYNC_PREFIX)} ${match[1]}`);
136
+ }
111
137
  } else {
112
138
  // Print any other notifications
113
139
  console.log(line);
114
140
  }
115
141
  });
116
142
 
117
- const rlErr = readline.createInterface({
118
- input: browserSync.stderr,
119
- crlfDelay: Infinity,
143
+ browserSync.stderr.on("data", (data) => {
144
+ console.error(`browser-sync error: ${data.toString()}`);
120
145
  });
121
146
 
122
- rlErr.on("line", (line) => {
123
- console.error(`browser-sync error: ${line}`);
147
+ browserSync.on("error", (err) => {
148
+ console.error(`Failed to start browserSync process: ${err.message}`);
124
149
  });
125
150
 
126
151
  // Function to start _dev process
127
152
  function startDevProcess() {
128
153
  console.log("Starting _dev...");
129
- const devProcess = exec("npm run _dev");
154
+ devProcess = spawn("npm", ["run", "_dev"], { shell: true });
130
155
 
131
156
  devProcess.stdout.on("data", (data) => {
132
157
  process.stdout.write(data);
@@ -139,14 +164,39 @@ async function startDev() {
139
164
  devProcess.on("close", (code) => {
140
165
  console.log(`Dev process exited with code ${code}`);
141
166
  });
167
+
168
+ devProcess.on("error", (err) => {
169
+ console.error(`Failed to start dev process: ${err.message}`);
170
+ });
142
171
  }
143
172
 
144
173
  // Handle browserSync close event
145
174
  browserSync.on("close", (code) => {
146
175
  console.log(`browserSync process exited with code ${code}`);
147
176
  });
177
+
178
+ // Handle process exit and cleanup
179
+ function handleExit() {
180
+ if (browserSync) {
181
+ browserSync.kill();
182
+ }
183
+ if (devProcess) {
184
+ devProcess.kill();
185
+ }
186
+ }
187
+
188
+ process.on("exit", handleExit);
189
+ process.on("SIGINT", () => {
190
+ handleExit();
191
+ process.exit();
192
+ });
193
+ process.on("SIGTERM", () => {
194
+ handleExit();
195
+ process.exit();
196
+ });
148
197
  } catch (error) {
149
198
  console.error("An error occurred:", error.message);
199
+ process.exit(1);
150
200
  }
151
201
  }
152
202
 
@@ -3,6 +3,7 @@ import { writeFileSync } from "fs";
3
3
  import { fileURLToPath } from "url";
4
4
  import { join, dirname } from "path";
5
5
  import { readFileSync } from "fs";
6
+ import chalk from "chalk";
6
7
 
7
8
  // Define __dirname equivalent in ES modules
8
9
  const __filename = fileURLToPath(import.meta.url);
@@ -47,7 +48,9 @@ const swaggerSpec = JSON.stringify(swaggerJsdoc(options), null, 2);
47
48
  try {
48
49
  writeFileSync(outputPath, swaggerSpec, "utf-8");
49
50
  console.log(
50
- `Swagger JSON has been generated and saved to /src/app/swagger-docs/pphp-swagger.json`
51
+ `Swagger JSON has been generated and saved to ${chalk.blue(
52
+ "src/app/swagger-docs/pphp-swagger.json"
53
+ )}`
51
54
  );
52
55
  } catch (error) {
53
56
  console.error("Error saving Swagger JSON:", error);
@@ -1,7 +1,7 @@
1
1
  <div class="flex flex-col min-h-[100vh] bg-gradient-to-b from-[#a1b8c2] to-white dark:from-[#334455] dark:to-black">
2
2
  <header class="px-4 lg:px-6 h-14 flex items-center">
3
3
  <a class="flex items-center justify-center" href="/">
4
- <img class="h-10 w-10" src="<?= $baseUrl ?>assets/images/prisma-php.png" alt="Prisma PHP">
4
+ <img class="h-10 w-10" src="<?php echo $baseUrl ?>/assets/images/prisma-php.png" alt="Prisma PHP">
5
5
  <span class="sr-only">Prisma PHP</span>
6
6
  </a>
7
7
  <nav class="ml-auto flex gap-4 sm:gap-6">
@@ -24,7 +24,7 @@
24
24
  <div class="px-4 md:px-6">
25
25
  <div class="flex flex-col items-center space-y-4 text-center">
26
26
  <h1 class="text-3xl font-bold tracking-tighter sm:text-4xl md:text-5xl lg:text-6xl/none flex items-center gap-3 justify-center">
27
- Welcome to Prisma PHP <img class="h-20 w-20 hidden sm:block" src="<?= $baseUrl ?>assets/images/prisma-php.png" alt="Prisma PHP">
27
+ Welcome to Prisma PHP <img class="h-20 w-20 hidden sm:block" src="<?php echo $baseUrl ?>/assets/images/prisma-php.png" alt="Prisma PHP">
28
28
  </h1>
29
29
  <p class="mx-auto max-w-[700px] text-gray-500 md:text-xl dark:text-gray-400">
30
30
  The Next Generation ORM for PHP
@@ -1,4 +1,15 @@
1
+ <?php
2
+
3
+ $mainLayoutHead = [
4
+ "<link rel='stylesheet' type='text/css' href='$baseUrl/swagger-docs/dist/swagger-ui.css' />",
5
+ "<link rel='stylesheet' type='text/css' href='$baseUrl/swagger-docs/dist/index.css' />",
6
+ "<link rel='icon' type='image/png' href='$baseUrl/swagger-docs/dist/favicon-32x32.png' sizes='32x32' />",
7
+ "<link rel='icon' type='image/png' href='$baseUrl/swagger-docs/dist/favicon-16x16.png' sizes='16x16' />",
8
+ ]
9
+
10
+ ?>
11
+
1
12
  <div id="swagger-ui"></div>
2
- <script src="<?= $baseUrl ?>swagger-docs/dist/swagger-ui-bundle.js" charset="UTF-8"> </script>
3
- <script src="<?= $baseUrl ?>swagger-docs/dist/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
4
- <script src="<?= $baseUrl ?>swagger-docs/dist/swagger-initializer.js" charset="UTF-8"> </script>
13
+ <script src="<?php echo $baseUrl ?>/swagger-docs/dist/swagger-ui-bundle.js" charset="UTF-8"> </script>
14
+ <script src="<?php echo $baseUrl ?>/swagger-docs/dist/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
15
+ <script src="<?php echo $baseUrl ?>/swagger-docs/dist/swagger-initializer.js" charset="UTF-8"> </script>
@@ -3,15 +3,13 @@
3
3
 
4
4
  <head>
5
5
  <meta charset="UTF-8">
6
- <title>Swagger UI</title>
7
- <link rel="stylesheet" type="text/css" href="<?= $baseUrl ?>swagger-docs/dist/swagger-ui.css" />
8
- <link rel="stylesheet" type="text/css" href="<?= $baseUrl ?>swagger-docs/dist/index.css" />
9
- <link rel="icon" type="image/png" href="<?= $baseUrl ?>swagger-docs/dist/favicon-32x32.png" sizes="32x32" />
10
- <link rel="icon" type="image/png" href="<?= $baseUrl ?>swagger-docs/dist/favicon-16x16.png" sizes="16x16" />
6
+ <title>Prisma PHP Swagger UI</title>
11
7
  </head>
12
8
 
13
9
  <body>
14
10
  <?php echo $content; ?>
11
+ <!-- Dynamic Footer -->
12
+ <?php echo implode("\n", $mainLayoutFooter); ?>
15
13
  </body>
16
14
 
17
15
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.20.516",
3
+ "version": "1.20.518",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",