Actions & Responses
There are no controllers. Every route points to one action — a class extending SystemHttpAction with a two-method contract.
The action contract
| Method | Required | Purpose |
|---|---|---|
main() | yes | Called on every successful request, after all middlewares pass. Receives the route params. Return value is echoed. |
middlewares() | yes | Returns an array of middleware class names that guard this action. |
boot() | no | Runs before the middleware pipeline. Use for setup shared by the action. |
<?php
namespace App\Actions;
use System\Http\Action;
use System\Logs\Log;
class HelloWorld extends Action {
public function boot() {
// e.g. shared setup
}
public function middlewares() {
return []; // no middlewares for this action
}
public function main() {
Log::debug("This is a message");
return response()
->view("welcome")
->render();
}
}
Reading the request
The Action base class captures the incoming request so you can read input directly:
| Method | Description |
|---|---|
all() | Merged query + body/data array ($_GET + $_POST + JSON body). Body wins on key collisions. |
input($key, $default) | A value from $_POST / the JSON body. |
get($key, $default) | A value from $_GET (query string). |
data($key) | Returns a chainable System\Support\Str wrapper. |
header($key, $default) | A request header (case-insensitive). With no args, returns all headers. |
$this->files | The $_FILES array. |
public function main() {
$name = $this->input("name"); // from body
$page = $this->get("page", 1); // from query string
$token = $this->header("X-CSRF-TOKEN"); // request header
$all = $this->all(); // everything merged
$length = $this->data("length")->int()->value(); // chainable string handling
return response()->json([
"name" => $name,
"page" => $page,
]);
}
The Str value object
Action::data($key) returns a System\Support\Str object with chainable methods:
| Method | Description |
|---|---|
trim() | trim() the value. |
sanitize() | htmlspecialchars($value, ENT_QUOTES, "UTF-8"). |
int() | Cast to integer. |
value() | Return the final value. |
$this->data("email")->trim()->sanitize()->value();
$this->data("age")->int()->value(); // 25
sanitize() raises a TypeError when the underlying value is null — guard with ?? null or an if before chaining it on optional fields.
Responses
Build responses with the response() helper (a System\Http\Response instance). Responses are fluent and, for data responses, send (echo) immediately.
JSON
return response()->json(["data" => $data, "ok" => true]);
Text & HTML
return response()->text("This is plain text");
return response()->html("<h1>Hello World</h1>");
Views
response()->view() returns a view renderer — call render() to produce the output:
return response()
->view("welcome") // views/welcome.php
->render();
// with data
return response()
->view("post", ["title" => "My Post"])
->render();
There is no global view() helper — always go through response()->view(...)->render().
Redirects
return response()->redirect("/dashboard"); // 302
return response()->redirect("/login", 301);
return response()->back(); // HTTP_REFERER, or "/"
Status & headers
return response()
->status(201)
->header("X-Custom", "value")
->json(["created" => true]);
send() calls http_response_code(), sets each registered header and echoes the body. json/text/html all send automatically.
response()->view() returns a ViewRender, so any
status()/header() configured on the response is ignored.
Set the status on the renderer instead — and only the three
Error enum values are accepted:
return response()->view("errors/404")
->status(\System\Exceptions\Error::NOT_FOUND)
->render();
Part of the Lunaris documentation · Source on Codeberg · MIT License