Skip to content

Commit 597922b

Browse files
committed
Add rewriter support
1 parent 12f1269 commit 597922b

File tree

7 files changed

+1608
-85
lines changed

7 files changed

+1608
-85
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,28 @@ The stackable uses a `platformatic.json` configuration file:
4949
"$schema": "https://schemas.platformatic.dev/@platformatic/php/0.4.3.json",
5050
"module": "@platformatic/php",
5151
"php": {
52-
"docroot": "public"
52+
"docroot": "public",
53+
"rewriter": [
54+
{
55+
"operation": "and",
56+
"conditions": [
57+
{
58+
"type": "path",
59+
"args": ["^/api/.*"]
60+
},
61+
{
62+
"type": "method",
63+
"args": ["POST"]
64+
}
65+
],
66+
"rewriters": [
67+
{
68+
"type": "path",
69+
"args": ["api.php"]
70+
}
71+
]
72+
}
73+
]
5374
},
5475
"server": {
5576
"hostname": "{PLT_SERVER_HOSTNAME}",
@@ -64,6 +85,17 @@ The stackable uses a `platformatic.json` configuration file:
6485

6586
#### php
6687
- `docroot` (string, required) - Path to the root directory containing PHP files
88+
- `rewriter` (array, optional) - A sequence of conditional rewrites to apply to PHP requests
89+
- Each conditional rewrite is an object with:
90+
- `operation` (string, optional) - Either `and` or `or` to combine conditions, defaults to `and`.
91+
- `conditions` (array, optional) - List of conditions to match, if any
92+
- Each condition is an object with:
93+
- `type` (string, required) - Type of condition (e.g., `path`, `method`)
94+
- `args` (array, required) - Parameters for the condition
95+
- `rewriters` (array, required) - List of rewriters to apply if conditions match
96+
- Each rewriter is an object with:
97+
- `type` (string, required) - Type of rewriter (e.g., `path`, `method`)
98+
- `args` (array, required) - Parameters for the rewriter
6799

68100
#### server
69101
Standard Platformatic server configuration options are supported.
@@ -150,7 +182,7 @@ echo json_encode([
150182
// public/api.php
151183
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
152184
$input = json_decode(file_get_contents('php://input'), true);
153-
185+
154186
header("Content-Type: application/json");
155187
echo json_encode([
156188
"received" => $input,

0 commit comments

Comments
 (0)