Reference search
Results for "handlers"
Reference results link to the matching section. Follow its prerequisites before using a code extract.
From the matching guide
A Complete JSON Handler
Create src/Views/greeting.get.php : Request /greeting?name=Sam . Responses::json() sets the JSON content type and encodes the data. Arrays from query or form input are possible, so check types before treating a value as text.
<?php
declare(strict_types=1);
use CorianderCore\Core\Http\Responses;
use Psr\Http\Message\ServerRequestInterface;
return static function (ServerRequestInterface $request) {
$query = $request->getQueryParams();
$name = $query['name'] ?? 'visitor';
if (!is_string($name)) {
return Responses::json(['error' => 'name must be text.'], 422);
}
return Responses::json(['message' => 'Hello ' . $name]);
};
Request Handlers
A Complete JSON Handler
Create src/Views/greeting.get.php : Request /greeting?name=Sam . Responses::json() sets the JSON content type and encodes the data. Arrays from query or form input are possible, so check types before treating a value as text.
Core Concepts
Handlers
Handlers read request input, call reusable app logic, and select a response. Keep a tiny endpoint in the route file or delegate to an ordinary App\Actions class. The framework does not discover action classes automatically.
Custom Module Guide
Call It From A Handler
Replace src/Views/posts.get.php with this complete handler: The router calls the handler, the handler calls your repository, and the repository uses the framework database API. The handler chooses the JSON response; the repository knows not...
Recommended App Architecture
Recommended App Architecture
...In 0.4.1, pages and HTTP handlers share one private Views tree; classes and browser helpers remain ordinary app-owned code. Actions is a convention, not a special framework feature. A fixed page can be direct HTML in a GET file; a small JSO...
Assets And Images
Supported Image Options
...Unsafe attributes are ignored, including event-handler attributes such as onclick , and generated source attributes such as src and srcset .
Route Cache
Route Cache
...This replaces controller-cache generation.
CLI Guide
Create Routes And Views
...The controller generator and manual route registration were removed in 0.3.0. Write small route handlers or ordinary app-owned action classes instead.
Database Module Guide
Database Module Guide
...A handler is created lazily on the first SQL call; no service-container registration is needed in 0.4.1. For tests or a custom connection lifecycle, inject a handler with SQLManager::setDatabaseHandler($handler) before querying. Keep the co...
Database Patterns
Recommended Decision
...Use repositories when the same data access appears in more than one handler.
Errors And Debugging
Errors And Debugging
First identify whether the request reaches PHP, the router, middleware, or the handler. Do not disable protection to make an error disappear.
Dynamic View Guide
First Build A Direct Page
...Use the handler approach below when you need a real 404, a redirect, or another response status.
Install CorianderPHP
Next Steps
...After installation, create your first route and view: Routing Request Handlers Views Recommended App Architecture
Middleware
Middleware
Middleware runs before and after a selected route handler. Use it for request gates such as authentication, authorization, request limits, and response headers. In 0.4.1, middleware is declared in route-directory _middleware.php files, not ...
Production Checklist
Document Root And Private Files
...Restrict directly executable PHP to the front controller. Test both source exposure and real asset URLs.
Request Lifecycle
Request Lifecycle
...1 Front controller public/index.php loads configuration and the framework autoloader. 2 Request factory RequestFactory::fromGlobals() bounds the body and parses query, form/JSON, cookies, and uploads. 3 Router Router::handle() selects a dis...
File-Based Routing
Create Your First Route
...Non-GET files must return callable handlers. Never mix printed HTML and a returned handler in one file. Creating these files by hand is also supported. Generators are conveniences, not a registration step.
Security Guide
Route And Template Safety
...Use directory middleware for protected areas, including all write handlers. Filenames with private prefixes are not routes. View paths must be normalized relative names under src/Views . Do not build them from raw request values. The render...
Authentication, Sessions And Flash Messages
Login And Logout
...2 Verify the POST CSRF middleware validates the request; your handler validates input and verifies a stored password hash. 3 Store identity Start the session, rotate its ID, and store the database user ID, never a submitted role. 4 Protect ...
Static View Guide
Static View Guide
...CorianderPHP 0.4.1 can render it directly from a GET file, without a forwarding handler.
Testing An App
Route Smoke Test
...The router test exercises middleware and handlers, not the front controller's parsing or HTTP emission; add an HTTP check for those boundaries. For JSON integration requests, use RequestFactory::fromGlobals() or set withParsedBody($payload)...
Upgrade Guide
Upgrade From 0.4.0 To 0.4.1
...See Request Handlers . CSS/JavaScript version strings are opaque content hashes, not timestamps. Pass raw relative paths to PublicUrl::versionedAsset() rather than pre-encoding them. Unmarked files use content hashing; rebuilt files use bou...
View Overview
Direct GET Or Explicit Response?
...Do not mix printed HTML with a returned handler. For prepared data and a separate template, return Responses::view('articles/show', $data) . This explicit view rendering includes layouts and ancestor directory scripts unless layout: false ....