create-prisma-php-app 1.20.521 → 1.20.523
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 +4 -3
- package/dist/index.js +6 -8
- package/dist/src/Lib/Headers/Boom.php +174 -0
- package/dist/src/app/index.php +3 -3
- package/dist/src/app/layout.php +5 -5
- package/dist/src/app/swagger-docs/apis/pphp-swagger.json +1 -1
- package/dist/src/app/swagger-docs/apis/users.js +6 -6
- package/dist/swagger-docs-index.php +3 -3
- package/dist/swagger-docs-layout.php +2 -2
- package/package.json +1 -1
package/dist/bootstrap.php
CHANGED
|
@@ -661,7 +661,7 @@ try {
|
|
|
661
661
|
authenticateUserToken();
|
|
662
662
|
|
|
663
663
|
if (empty($_contentToInclude)) {
|
|
664
|
-
if (!$isXFilRequest) {
|
|
664
|
+
if (!$isXFilRequest && $_prismaPHPSettings['backendOnly'] === "true") {
|
|
665
665
|
// Set the header and output a JSON response for permission denied
|
|
666
666
|
header('Content-Type: application/json');
|
|
667
667
|
echo json_encode([
|
|
@@ -684,7 +684,8 @@ try {
|
|
|
684
684
|
header('Content-Type: ' . mime_content_type($filePath)); // Dynamic content type
|
|
685
685
|
readfile($filePath);
|
|
686
686
|
}
|
|
687
|
-
|
|
687
|
+
exit;
|
|
688
|
+
} else if ($_prismaPHPSettings['backendOnly'] === "true") {
|
|
688
689
|
// Set the header and output a JSON response for file not found
|
|
689
690
|
header('Content-Type: application/json');
|
|
690
691
|
echo json_encode([
|
|
@@ -692,8 +693,8 @@ try {
|
|
|
692
693
|
'error' => 'Not found'
|
|
693
694
|
]);
|
|
694
695
|
http_response_code(404); // Set HTTP status code to 404 Not Found
|
|
696
|
+
exit;
|
|
695
697
|
}
|
|
696
|
-
exit;
|
|
697
698
|
}
|
|
698
699
|
|
|
699
700
|
if (!empty($_contentToInclude) && basename($_contentToInclude) === 'route.php') {
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ module.exports = {
|
|
|
90
90
|
notify: false,
|
|
91
91
|
open: false,
|
|
92
92
|
ghostMode: false,
|
|
93
|
+
codeSync: true, // Disable synchronization of code changes across clients
|
|
93
94
|
};`;
|
|
94
95
|
// Determine the path and write the bs-config.js
|
|
95
96
|
const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
|
|
@@ -142,6 +143,7 @@ async function updatePackageJson(baseDir, answer) {
|
|
|
142
143
|
Object.assign({}, packageJson.scripts),
|
|
143
144
|
{ "create-swagger-docs": "node settings/swagger-setup.js" }
|
|
144
145
|
);
|
|
146
|
+
answersToInclude.push("create-swagger-docs");
|
|
145
147
|
}
|
|
146
148
|
// Initialize with existing scripts
|
|
147
149
|
let updatedScripts = Object.assign({}, packageJson.scripts);
|
|
@@ -240,11 +242,7 @@ function copyRecursiveSync(src, dest, answer) {
|
|
|
240
242
|
(answer.backendOnly && destLower.includes("src\\app\\css"))
|
|
241
243
|
)
|
|
242
244
|
return;
|
|
243
|
-
if (
|
|
244
|
-
answer.backendOnly &&
|
|
245
|
-
!answer.swaggerDocs &&
|
|
246
|
-
destLower.includes("src\\app\\swagger-docs")
|
|
247
|
-
)
|
|
245
|
+
if (!answer.swaggerDocs && destLower.includes("src\\app\\swagger-docs"))
|
|
248
246
|
return;
|
|
249
247
|
const destModified = dest.replace(/\\/g, "/");
|
|
250
248
|
if (
|
|
@@ -345,13 +343,13 @@ function modifyLayoutPHP(baseDir, answer) {
|
|
|
345
343
|
let indexContent = fs.readFileSync(layoutPath, "utf8");
|
|
346
344
|
let stylesAndLinks = "";
|
|
347
345
|
if (!answer.backendOnly) {
|
|
348
|
-
stylesAndLinks = `\n <link href="
|
|
346
|
+
stylesAndLinks = `\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"></script>`;
|
|
349
347
|
}
|
|
350
348
|
// Tailwind CSS link or CDN script
|
|
351
349
|
let tailwindLink = "";
|
|
352
350
|
if (!answer.backendOnly) {
|
|
353
351
|
tailwindLink = answer.tailwindcss
|
|
354
|
-
? ` <link href="
|
|
352
|
+
? ` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
|
|
355
353
|
: ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
|
|
356
354
|
}
|
|
357
355
|
// Insert before the closing </head> tag
|
|
@@ -359,7 +357,7 @@ function modifyLayoutPHP(baseDir, answer) {
|
|
|
359
357
|
indexContent = indexContent.replace(
|
|
360
358
|
"</head>",
|
|
361
359
|
`${tailwindLink}${breakLine} <!-- Dynamic Head -->
|
|
362
|
-
|
|
360
|
+
<?= implode("\\n", $mainLayoutHead); ?>
|
|
363
361
|
</head>`
|
|
364
362
|
);
|
|
365
363
|
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
|
+
}
|
package/dist/src/app/index.php
CHANGED
|
@@ -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="
|
|
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="
|
|
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">©
|
|
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
|
package/dist/src/app/layout.php
CHANGED
|
@@ -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="
|
|
8
|
-
<title
|
|
9
|
-
<link rel="icon" href="
|
|
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
|
-
|
|
13
|
+
<?= $content; ?>
|
|
14
14
|
<!-- Dynamic Footer -->
|
|
15
|
-
|
|
15
|
+
<?= implode("\n", $mainLayoutFooter); ?>
|
|
16
16
|
</body>
|
|
17
17
|
|
|
18
18
|
</html>
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* required: true
|
|
47
47
|
* description: The user ID
|
|
48
48
|
* schema:
|
|
49
|
-
* type:
|
|
49
|
+
* type: string
|
|
50
50
|
* responses:
|
|
51
51
|
* 200:
|
|
52
52
|
* description: A single user object
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* @swagger
|
|
73
|
-
* /users:
|
|
73
|
+
* /users/create:
|
|
74
74
|
* post:
|
|
75
75
|
* summary: Create a new user
|
|
76
76
|
* tags:
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* @swagger
|
|
115
|
-
* /users/{id}:
|
|
115
|
+
* /users/update/{id}:
|
|
116
116
|
* put:
|
|
117
117
|
* summary: Update a user by ID
|
|
118
118
|
* tags:
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
* required: true
|
|
124
124
|
* description: The user ID
|
|
125
125
|
* schema:
|
|
126
|
-
* type:
|
|
126
|
+
* type: string
|
|
127
127
|
* requestBody:
|
|
128
128
|
* required: true
|
|
129
129
|
* content:
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* @swagger
|
|
163
|
-
* /users/{id}:
|
|
163
|
+
* /users/delete/{id}:
|
|
164
164
|
* delete:
|
|
165
165
|
* summary: Delete a user by ID
|
|
166
166
|
* tags:
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
* required: true
|
|
172
172
|
* description: The user ID
|
|
173
173
|
* schema:
|
|
174
|
-
* type:
|
|
174
|
+
* type: string
|
|
175
175
|
* responses:
|
|
176
176
|
* 204:
|
|
177
177
|
* description: User successfully deleted
|
|
@@ -10,6 +10,6 @@ $mainLayoutHead = [
|
|
|
10
10
|
?>
|
|
11
11
|
|
|
12
12
|
<div id="swagger-ui"></div>
|
|
13
|
-
<script src="
|
|
14
|
-
<script src="
|
|
15
|
-
<script src="
|
|
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>
|