create-prisma-php-app 1.20.521 → 1.20.522

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/index.js CHANGED
@@ -142,6 +142,7 @@ async function updatePackageJson(baseDir, answer) {
142
142
  Object.assign({}, packageJson.scripts),
143
143
  { "create-swagger-docs": "node settings/swagger-setup.js" }
144
144
  );
145
+ answersToInclude.push("create-swagger-docs");
145
146
  }
146
147
  // Initialize with existing scripts
147
148
  let updatedScripts = Object.assign({}, packageJson.scripts);
@@ -345,13 +346,13 @@ function modifyLayoutPHP(baseDir, answer) {
345
346
  let indexContent = fs.readFileSync(layoutPath, "utf8");
346
347
  let stylesAndLinks = "";
347
348
  if (!answer.backendOnly) {
348
- stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>/js/index.js"></script>`;
349
+ stylesAndLinks = `\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"></script>`;
349
350
  }
350
351
  // Tailwind CSS link or CDN script
351
352
  let tailwindLink = "";
352
353
  if (!answer.backendOnly) {
353
354
  tailwindLink = answer.tailwindcss
354
- ? ` <link href="<?php echo $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
355
+ ? ` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
355
356
  : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
356
357
  }
357
358
  // Insert before the closing </head> tag
@@ -359,7 +360,7 @@ function modifyLayoutPHP(baseDir, answer) {
359
360
  indexContent = indexContent.replace(
360
361
  "</head>",
361
362
  `${tailwindLink}${breakLine} <!-- Dynamic Head -->
362
- <?php echo implode("\\n", $mainLayoutHead); ?>
363
+ <?= implode("\\n", $mainLayoutHead); ?>
363
364
  </head>`
364
365
  );
365
366
  fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
@@ -0,0 +1,174 @@
1
+ <?php
2
+
3
+ namespace Lib\Headers;
4
+
5
+ /**
6
+ * Class Boom
7
+ *
8
+ * A helper class for generating standardized HTTP error responses.
9
+ *
10
+ * @package Lib\Headers
11
+ */
12
+ class Boom
13
+ {
14
+ /**
15
+ * HTTP status code.
16
+ *
17
+ * @var int
18
+ */
19
+ protected int $statusCode;
20
+
21
+ /**
22
+ * Error message.
23
+ *
24
+ * @var string
25
+ */
26
+ protected string $errorMessage;
27
+
28
+ /**
29
+ * Additional error details.
30
+ *
31
+ * @var array
32
+ */
33
+ protected array $errorDetails;
34
+
35
+ /**
36
+ * Boom constructor.
37
+ *
38
+ * @param int $statusCode HTTP status code.
39
+ * @param string $errorMessage Error message.
40
+ * @param array $errorDetails Additional error details.
41
+ */
42
+ public function __construct(int $statusCode, string $errorMessage, array $errorDetails = [])
43
+ {
44
+ $this->statusCode = $statusCode;
45
+ $this->errorMessage = $errorMessage;
46
+ $this->errorDetails = $errorDetails;
47
+ }
48
+
49
+ /**
50
+ * Factory method for 400 Bad Request.
51
+ *
52
+ * @param string $message Error message.
53
+ * @param array $details Additional error details.
54
+ *
55
+ * @return self
56
+ */
57
+ public static function badRequest(string $message = 'Bad Request', array $details = []): self
58
+ {
59
+ return new self(400, $message, $details);
60
+ }
61
+
62
+ /**
63
+ * Factory method for 401 Unauthorized.
64
+ *
65
+ * @param string $message Error message.
66
+ * @param array $details Additional error details.
67
+ *
68
+ * @return self
69
+ */
70
+ public static function unauthorized(string $message = 'Unauthorized', array $details = []): self
71
+ {
72
+ return new self(401, $message, $details);
73
+ }
74
+
75
+ /**
76
+ * Factory method for 403 Forbidden.
77
+ *
78
+ * @param string $message Error message.
79
+ * @param array $details Additional error details.
80
+ *
81
+ * @return self
82
+ */
83
+ public static function forbidden(string $message = 'Forbidden', array $details = []): self
84
+ {
85
+ return new self(403, $message, $details);
86
+ }
87
+
88
+ /**
89
+ * Factory method for 404 Not Found.
90
+ *
91
+ * @param string $message Error message.
92
+ * @param array $details Additional error details.
93
+ *
94
+ * @return self
95
+ */
96
+ public static function notFound(string $message = 'Not Found', array $details = []): self
97
+ {
98
+ return new self(404, $message, $details);
99
+ }
100
+
101
+ /**
102
+ * Factory method for 500 Internal Server Error.
103
+ *
104
+ * @param string $message Error message.
105
+ * @param array $details Additional error details.
106
+ *
107
+ * @return self
108
+ */
109
+ public static function internal(string $message = 'Internal Server Error', array $details = []): self
110
+ {
111
+ return new self(500, $message, $details);
112
+ }
113
+
114
+ /**
115
+ * Sends the HTTP error response and terminates the script.
116
+ *
117
+ * @return void
118
+ */
119
+ public function toResponse(): void
120
+ {
121
+ http_response_code($this->statusCode);
122
+ header('Content-Type: application/json');
123
+
124
+ echo json_encode([
125
+ 'statusCode' => $this->statusCode,
126
+ 'error' => $this->errorMessage,
127
+ 'details' => $this->errorDetails,
128
+ ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
129
+
130
+ exit; // Ensures no further execution after sending the response
131
+ }
132
+
133
+ /**
134
+ * Checks if the provided error is an instance of Boom.
135
+ *
136
+ * @param mixed $error The error to check.
137
+ *
138
+ * @return bool
139
+ */
140
+ public static function isBoom($error): bool
141
+ {
142
+ return $error instanceof self;
143
+ }
144
+
145
+ /**
146
+ * Gets the HTTP status code.
147
+ *
148
+ * @return int
149
+ */
150
+ public function getStatusCode(): int
151
+ {
152
+ return $this->statusCode;
153
+ }
154
+
155
+ /**
156
+ * Gets the error message.
157
+ *
158
+ * @return string
159
+ */
160
+ public function getErrorMessage(): string
161
+ {
162
+ return $this->errorMessage;
163
+ }
164
+
165
+ /**
166
+ * Gets the additional error details.
167
+ *
168
+ * @return array
169
+ */
170
+ public function getErrorDetails(): array
171
+ {
172
+ return $this->errorDetails;
173
+ }
174
+ }
@@ -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="<?php echo $baseUrl ?>/assets/images/prisma-php.png" alt="Prisma PHP">
4
+ <img class="h-10 w-10" src="<?= $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="<?php echo $baseUrl ?>/assets/images/prisma-php.png" alt="Prisma PHP">
27
+ Welcome to Prisma PHP <img class="h-20 w-20 hidden sm:block" src="<?= $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
@@ -37,7 +37,7 @@
37
37
  </section>
38
38
  </main>
39
39
  <footer class="flex flex-col gap-2 sm:flex-row py-6 w-full shrink-0 items-center px-4 md:px-6 border-t">
40
- <p class="text-xs text-gray-500 dark:text-gray-400">© <?php echo date("Y"); ?> Prisma PHP. All rights reserved.</p>
40
+ <p class="text-xs text-gray-500 dark:text-gray-400">© <?= date("Y"); ?> Prisma PHP. All rights reserved.</p>
41
41
  <nav class="sm:ml-auto flex gap-4 sm:gap-6">
42
42
  <a class="text-xs hover:underline underline-offset-4" href="#">
43
43
  Twitter
@@ -4,15 +4,15 @@
4
4
  <head>
5
5
  <meta charset="UTF-8">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <meta name="pp-description" content="<?php echo htmlspecialchars($metadata['description']); ?>">
8
- <title><?php echo htmlspecialchars($metadata['title']); ?></title>
9
- <link rel="icon" href="<?php echo $baseUrl; ?>\favicon.ico" type="image/x-icon">
7
+ <meta name="pp-description" content="<?= htmlspecialchars($metadata['description']); ?>">
8
+ <title><?= htmlspecialchars($metadata['title']); ?></title>
9
+ <link rel="icon" href="<?= $baseUrl; ?>\favicon.ico" type="image/x-icon">
10
10
  </head>
11
11
 
12
12
  <body>
13
- <?php echo $content; ?>
13
+ <?= $content; ?>
14
14
  <!-- Dynamic Footer -->
15
- <?php echo implode("\n", $mainLayoutFooter); ?>
15
+ <?= implode("\n", $mainLayoutFooter); ?>
16
16
  </body>
17
17
 
18
18
  </html>
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "servers": [
9
9
  {
10
- "url": "http://localhost:3004",
10
+ "url": "http://localhost:3000",
11
11
  "description": "Development Server"
12
12
  },
13
13
  {
@@ -10,6 +10,6 @@ $mainLayoutHead = [
10
10
  ?>
11
11
 
12
12
  <div id="swagger-ui"></div>
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>
13
+ <script src="<?= $baseUrl ?>/swagger-docs/dist/swagger-ui-bundle.js" charset="UTF-8"> </script>
14
+ <script src="<?= $baseUrl ?>/swagger-docs/dist/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
15
+ <script src="<?= $baseUrl ?>/swagger-docs/dist/swagger-initializer.js" charset="UTF-8"> </script>
@@ -7,9 +7,9 @@
7
7
  </head>
8
8
 
9
9
  <body>
10
- <?php echo $content; ?>
10
+ <?= $content; ?>
11
11
  <!-- Dynamic Footer -->
12
- <?php echo implode("\n", $mainLayoutFooter); ?>
12
+ <?= implode("\n", $mainLayoutFooter); ?>
13
13
  </body>
14
14
 
15
15
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.20.521",
3
+ "version": "1.20.522",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",