create-prisma-php-app 1.20.520 → 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/.htaccess +1 -1
- package/dist/bootstrap.php +3 -1
- package/dist/index.js +7 -4
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-client-php/index.js +6 -2
- package/dist/src/Lib/Auth/Auth.php +9 -0
- package/dist/src/Lib/Headers/Boom.php +174 -0
- package/dist/src/Lib/StateManager.php +9 -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 +24 -24
- package/dist/swagger-docs-index.php +3 -3
- package/dist/swagger-docs-layout.php +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as fs from"fs";import{exec}from"child_process";import path from"path";import{fileURLToPath}from"url";import CryptoJS from"crypto-js";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),getSecretKey=()=>{const r=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(r.length<400)throw new Error("File content is less than 400 characters.");return r.substring(247,289)},decryptData=(r,t)=>CryptoJS.AES.decrypt(r,t).toString(CryptoJS.enc.Utf8);
|
|
1
|
+
import*as fs from"fs";import{exec}from"child_process";import path from"path";import{fileURLToPath}from"url";import CryptoJS from"crypto-js";import chalk from"chalk";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),getSecretKey=()=>{const r=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(r.length<400)throw new Error("File content is less than 400 characters.");return r.substring(247,289)},decryptData=(r,t)=>CryptoJS.AES.decrypt(r,t).toString(CryptoJS.enc.Utf8);
|
|
2
2
|
const executePHP = (command) => {
|
|
3
3
|
exec(command, (error, stdout, stderr) => {
|
|
4
4
|
if (error) {
|
|
@@ -9,7 +9,11 @@ const executePHP = (command) => {
|
|
|
9
9
|
console.error(`Standard error: ${stderr}`);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
if (stdout.includes("Result: Prisma schema is valid.")) {
|
|
13
|
+
console.error(chalk.blue(stdout));
|
|
14
|
+
} else {
|
|
15
|
+
console.log(`Standard output...\n${stdout}`);
|
|
16
|
+
}
|
|
13
17
|
});
|
|
14
18
|
};
|
|
15
19
|
const main=async()=>{try{const e=process.cwd(),n=path.join(e,"prisma-php.json"),a=fs.readFileSync(n,{encoding:"utf8"}),c=JSON.parse(a),t=c.phpGenerateClassPath,i=`${__dirname}/index.php`,p=`${__dirname}/index.enc`,s=getSecretKey(),r=fs.readFileSync(p,{encoding:"utf8"}),d=decryptData(r,s);fs.writeFileSync(`${__dirname}/index.php`,d);const h=`${c.phpRootPathExe} ${i} ${t}`;executePHP(h)}catch(e){}};main().catch((e=>{}));
|
|
@@ -22,11 +22,20 @@ class Auth
|
|
|
22
22
|
private $secretKey;
|
|
23
23
|
private $defaultTokenValidity = '1h'; // Default to 1 hour
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Private constructor to prevent direct instantiation.
|
|
27
|
+
* Use Auth::getInstance() to get the singleton instance.
|
|
28
|
+
*/
|
|
25
29
|
private function __construct()
|
|
26
30
|
{
|
|
27
31
|
$this->secretKey = $_ENV['AUTH_SECRET'];
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Returns the singleton instance of the Auth class.
|
|
36
|
+
*
|
|
37
|
+
* @return Auth The singleton instance.
|
|
38
|
+
*/
|
|
30
39
|
public static function getInstance(): Auth
|
|
31
40
|
{
|
|
32
41
|
if (self::$instance === null) {
|
|
@@ -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
|
+
}
|
|
@@ -12,6 +12,10 @@ class StateManager
|
|
|
12
12
|
private array $state = [];
|
|
13
13
|
private array $listeners = [];
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new instance of the StateManager class.
|
|
17
|
+
* Use StateManager::getInstance() to get the singleton instance.
|
|
18
|
+
*/
|
|
15
19
|
private function __construct()
|
|
16
20
|
{
|
|
17
21
|
global $isWire;
|
|
@@ -23,6 +27,11 @@ class StateManager
|
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Gets the singleton instance of the StateManager class.
|
|
32
|
+
*
|
|
33
|
+
* @return StateManager The singleton instance of the StateManager class.
|
|
34
|
+
*/
|
|
26
35
|
public static function getInstance(): StateManager
|
|
27
36
|
{
|
|
28
37
|
if (self::$instance === null) {
|
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>
|
|
@@ -8,20 +8,32 @@
|
|
|
8
8
|
"servers": [
|
|
9
9
|
{
|
|
10
10
|
"url": "http://localhost:3000",
|
|
11
|
-
"description": "Server"
|
|
11
|
+
"description": "Development Server"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
"url": "your-domain",
|
|
15
|
-
"description": "Server"
|
|
14
|
+
"url": "your-production-domain",
|
|
15
|
+
"description": "Production Server"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"components": {
|
|
19
|
+
"securitySchemes": {
|
|
20
|
+
"bearerAuth": {
|
|
21
|
+
"type": "http",
|
|
22
|
+
"scheme": "bearer",
|
|
23
|
+
"bearerFormat": "JWT"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"security": [
|
|
28
|
+
{
|
|
29
|
+
"bearerAuth": []
|
|
16
30
|
}
|
|
17
31
|
],
|
|
18
32
|
"paths": {
|
|
19
33
|
"/users": {
|
|
20
34
|
"get": {
|
|
21
35
|
"summary": "Retrieve a list of users",
|
|
22
|
-
"tags": [
|
|
23
|
-
"Users"
|
|
24
|
-
],
|
|
36
|
+
"tags": ["Users"],
|
|
25
37
|
"responses": {
|
|
26
38
|
"200": {
|
|
27
39
|
"description": "A list of users",
|
|
@@ -54,19 +66,14 @@
|
|
|
54
66
|
},
|
|
55
67
|
"post": {
|
|
56
68
|
"summary": "Create a new user",
|
|
57
|
-
"tags": [
|
|
58
|
-
"Users"
|
|
59
|
-
],
|
|
69
|
+
"tags": ["Users"],
|
|
60
70
|
"requestBody": {
|
|
61
71
|
"required": true,
|
|
62
72
|
"content": {
|
|
63
73
|
"application/json": {
|
|
64
74
|
"schema": {
|
|
65
75
|
"type": "object",
|
|
66
|
-
"required": [
|
|
67
|
-
"name",
|
|
68
|
-
"email"
|
|
69
|
-
],
|
|
76
|
+
"required": ["name", "email"],
|
|
70
77
|
"properties": {
|
|
71
78
|
"name": {
|
|
72
79
|
"type": "string",
|
|
@@ -112,9 +119,7 @@
|
|
|
112
119
|
"/users/{id}": {
|
|
113
120
|
"get": {
|
|
114
121
|
"summary": "Retrieve a single user by ID",
|
|
115
|
-
"tags": [
|
|
116
|
-
"Users"
|
|
117
|
-
],
|
|
122
|
+
"tags": ["Users"],
|
|
118
123
|
"parameters": [
|
|
119
124
|
{
|
|
120
125
|
"in": "path",
|
|
@@ -158,9 +163,7 @@
|
|
|
158
163
|
},
|
|
159
164
|
"put": {
|
|
160
165
|
"summary": "Update a user by ID",
|
|
161
|
-
"tags": [
|
|
162
|
-
"Users"
|
|
163
|
-
],
|
|
166
|
+
"tags": ["Users"],
|
|
164
167
|
"parameters": [
|
|
165
168
|
{
|
|
166
169
|
"in": "path",
|
|
@@ -224,9 +227,7 @@
|
|
|
224
227
|
},
|
|
225
228
|
"delete": {
|
|
226
229
|
"summary": "Delete a user by ID",
|
|
227
|
-
"tags": [
|
|
228
|
-
"Users"
|
|
229
|
-
],
|
|
230
|
+
"tags": ["Users"],
|
|
230
231
|
"parameters": [
|
|
231
232
|
{
|
|
232
233
|
"in": "path",
|
|
@@ -249,11 +250,10 @@
|
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
},
|
|
252
|
-
"components": {},
|
|
253
253
|
"tags": [
|
|
254
254
|
{
|
|
255
255
|
"name": "Users",
|
|
256
256
|
"description": "User management API"
|
|
257
257
|
}
|
|
258
258
|
]
|
|
259
|
-
}
|
|
259
|
+
}
|
|
@@ -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>
|