create-prisma-php-app 1.20.519 → 1.20.521
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 +78 -41
- package/dist/index.js +14 -7
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-client-php/index.js +6 -2
- package/dist/settings/public-functions.php +29 -0
- package/dist/settings/swagger-setup.js +17 -4
- package/dist/src/Lib/Auth/Auth.php +38 -6
- package/dist/src/Lib/StateManager.php +9 -0
- package/dist/src/app/route.php +2 -1
- package/dist/src/app/swagger-docs/apis/pphp-swagger.json +25 -25
- 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=>{}));
|
|
@@ -88,3 +88,32 @@ function isXFilRequest(): bool
|
|
|
88
88
|
|
|
89
89
|
return false;
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get the Bearer token from the Authorization header.
|
|
94
|
+
*
|
|
95
|
+
* @return string|null The Bearer token or null if not present.
|
|
96
|
+
*/
|
|
97
|
+
function getBearerToken(): ?string
|
|
98
|
+
{
|
|
99
|
+
// Normalize headers to handle case-insensitive keys
|
|
100
|
+
$headers = array_change_key_case(getallheaders(), CASE_LOWER);
|
|
101
|
+
$authHeader = $headers['authorization'] ?? null;
|
|
102
|
+
|
|
103
|
+
// If not found, try fetching it from $_SERVER as a fallback
|
|
104
|
+
if (!$authHeader && isset($_SERVER['HTTP_AUTHORIZATION'])) {
|
|
105
|
+
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Fallback for Apache servers
|
|
109
|
+
if (!$authHeader && isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
|
|
110
|
+
$authHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Check if the Authorization header is in the expected Bearer format
|
|
114
|
+
if ($authHeader && preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
|
|
115
|
+
return $matches[1];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
@@ -37,7 +37,6 @@ if (existsSync(bsConnectionInfo)) {
|
|
|
37
37
|
console.warn("bs-output.json not found, using default connection info.");
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
// Swagger options
|
|
41
40
|
const options = {
|
|
42
41
|
definition: {
|
|
43
42
|
openapi: "3.0.0",
|
|
@@ -49,11 +48,25 @@ const options = {
|
|
|
49
48
|
servers: [
|
|
50
49
|
{
|
|
51
50
|
url: jsonData.local, // For Development
|
|
52
|
-
description: "Server",
|
|
51
|
+
description: "Development Server",
|
|
53
52
|
},
|
|
54
53
|
{
|
|
55
|
-
url: "your-domain", // For Production
|
|
56
|
-
description: "Server",
|
|
54
|
+
url: "your-production-domain", // For Production
|
|
55
|
+
description: "Production Server",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
components: {
|
|
59
|
+
securitySchemes: {
|
|
60
|
+
bearerAuth: {
|
|
61
|
+
type: "http",
|
|
62
|
+
scheme: "bearer",
|
|
63
|
+
bearerFormat: "JWT",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
security: [
|
|
68
|
+
{
|
|
69
|
+
bearerAuth: [],
|
|
57
70
|
},
|
|
58
71
|
],
|
|
59
72
|
},
|
|
@@ -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) {
|
|
@@ -100,13 +109,22 @@ class Auth
|
|
|
100
109
|
*/
|
|
101
110
|
public function isAuthenticated(): bool
|
|
102
111
|
{
|
|
112
|
+
global $_fileToInclude;
|
|
113
|
+
|
|
103
114
|
if (!isset($_COOKIE[self::COOKIE_NAME])) {
|
|
104
115
|
unset($_SESSION[self::PAYLOAD]);
|
|
105
116
|
return false;
|
|
106
117
|
}
|
|
107
118
|
|
|
108
|
-
$
|
|
119
|
+
if ($_fileToInclude === 'route.php') {
|
|
120
|
+
$bearerToken = getBearerToken();
|
|
121
|
+
$verifyBearerToken = $this->verifyToken($bearerToken);
|
|
122
|
+
if (!$verifyBearerToken) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
109
126
|
|
|
127
|
+
$jwt = $_COOKIE[self::COOKIE_NAME];
|
|
110
128
|
$verifyToken = $this->verifyToken($jwt);
|
|
111
129
|
if ($verifyToken === false) {
|
|
112
130
|
return false;
|
|
@@ -148,17 +166,31 @@ class Auth
|
|
|
148
166
|
|
|
149
167
|
/**
|
|
150
168
|
* Verifies the JWT token and returns the decoded payload if the token is valid.
|
|
151
|
-
* If the token is invalid,
|
|
169
|
+
* If the token is invalid or expired, null is returned.
|
|
152
170
|
*
|
|
153
171
|
* @param string $jwt The JWT token to verify.
|
|
154
|
-
* @return object Returns the decoded payload if the token is valid.
|
|
172
|
+
* @return object|null Returns the decoded payload if the token is valid, or null if invalid or expired.
|
|
155
173
|
*/
|
|
156
|
-
public function verifyToken(string $jwt)
|
|
174
|
+
public function verifyToken(?string $jwt): ?object
|
|
157
175
|
{
|
|
158
176
|
try {
|
|
159
|
-
|
|
177
|
+
if (!$jwt) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
$token = JWT::decode($jwt, new Key($this->secretKey, 'HS256'));
|
|
182
|
+
|
|
183
|
+
if (empty($token->role)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (isset($token->exp) && time() >= $token->exp) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return $token;
|
|
160
192
|
} catch (\Exception) {
|
|
161
|
-
|
|
193
|
+
return null;
|
|
162
194
|
}
|
|
163
195
|
}
|
|
164
196
|
|
|
@@ -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/route.php
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
$welcome = 'Welcome to the Prisma PHP Backend Only Starter Kit! This starter kit provides a powerful foundation for building robust PHP applications with Prisma PHP ORM, a modern database toolkit. To create a new route, follow these steps:
|
|
4
4
|
1. Create a new folder inside the "src/app" directory with the name of your route.
|
|
5
|
-
2. Inside the newly created folder, create a route.php file
|
|
5
|
+
2. Inside the newly created folder, create a route.php file. src/app/your-route/route.php
|
|
6
|
+
3. Define your route logic inside the route.php file.
|
|
6
7
|
|
|
7
8
|
This will serve as your API endpoint for the newly created route. Feel free to customize and extend the functionality as needed. Happy coding!
|
|
8
9
|
|
|
@@ -7,21 +7,33 @@
|
|
|
7
7
|
},
|
|
8
8
|
"servers": [
|
|
9
9
|
{
|
|
10
|
-
"url": "http://localhost:
|
|
11
|
-
"description": "Server"
|
|
10
|
+
"url": "http://localhost:3004",
|
|
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
|
+
}
|