Download the PHP package luany/core without Composer
On this page you can find all versions of the php package luany/core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package core
Short Description Luany Core — Router, middleware pipeline and DI resolver hook for the Luany ecosystem.
License MIT
Homepage https://github.com/luany-ecosystem/luany-core
Informations about the package core
luany/core
HTTP Request/Response, Router, Middleware Pipeline, CORS, Rate Limiting, and Route Caching for the Luany ecosystem.
Version: v1.0.0 | PHP: >= 8.2 | License: MIT Author: António Ambrósio Ngola | Org: luany-ecosystem
Table of Contents
- Installation
- Request
- Response
- Router & Route Facade
- Middleware
- Rate Limiters
- Exceptions
- Changelog
1. Installation
2. Request
Class: Luany\Core\Http\Request
Method override: HTML forms may include a hidden _method field (PUT, PATCH, DELETE). fromGlobals() handles this automatically.
JSON body: If Content-Type: application/json, the body is parsed from php://input automatically.
Body-only helper: Request::body() returns only parsed body fields (POST/JSON), unlike all() which merges body + query.
3. Response
Class: Luany\Core\Http\Response
4. Router & Route Facade
Classes: Luany\Core\Routing\Router, Luany\Core\Routing\Route
Route is a static facade over the singleton Router instance.
Basic Registration
Controllers may return Response, string, or array (auto-JSON).
Route Parameters
Named Routes
Route Groups
Resource Routes
View Routes
Model Binding
Automatically resolve route parameters to model instances before the action is called.
Unbound parameters pass through as raw strings. Bindings match by parameter name.
Route Caching
Serializes the compiled route table to a PHP file. Only array-action routes ([Controller::class, 'method']) are cached — closure routes cannot be serialized.
5. Middleware
Pipeline
Implementing middleware:
CorsMiddleware
Behaviour: OPTIONS requests short-circuit with 204. Wildcard ['*'] + credentials echoes the actual Origin. Disallowed origins get no CORS headers. Subdomain wildcards (*.example.com) are supported.
RateLimitMiddleware
Exceeding the limit returns 429 with X-RateLimit-Limit, X-RateLimit-Remaining: 0, and Retry-After headers. Allowed requests receive X-RateLimit-Limit and X-RateLimit-Remaining.
Override keyFor(Request $request): string to key by user ID instead of IP.
6. Rate Limiters
InMemoryRateLimiter
Per-process static store. For tests and development only.
FileRateLimiter
JSON file-backed store. Safe for single-server production. Uses flock() for concurrency safety. Keys are SHA-256 hashed — no path traversal possible.
Custom RateLimiter
Implement Luany\Core\RateLimit\RateLimiterInterface:
7. Exceptions
| Exception | Code | When thrown |
|---|---|---|
RouteNotFoundException |
404 | No route URI matches the request |
MethodNotAllowedException |
405 | URI matches a route but the HTTP method does not |
MethodNotAllowedException::getAllowedMethods(): string[] — e.g. ['GET', 'POST']
MethodNotAllowedException::getAllowHeaderValue(): string — e.g. 'GET, POST'
8. Changelog
v1.0.0 — Phase 4: Core Hardening
New — src/Routing/RouteCache.php
store()— serialize route table to PHP file (closure routes excluded)load()— load cached route tableclear()— delete cache file
Modified — src/Routing/Router.php
- Two-pass dispatch: URI match + wrong method →
MethodNotAllowedException(405) instead of 404 bind(string $param, callable $resolver)— register route model bindinggetBindings(),getRoutes(),getNamedRoutes()— expose state for cache and testingsaveToCache()/loadFromCache()— route cache integration
Modified — src/Routing/Route.php
bind(),model()— model binding APIcache(),loadCache(),clearCache()— cache APIgroup(array $attributes, callable $callback)— combined prefix+middleware shorthandsetRouter(),reset()— testing helpers
Existing (shipped before Phase 4, now fully tested):
MethodNotAllowedException, CorsMiddleware, RateLimitMiddleware,
RateLimiterInterface, InMemoryRateLimiter, FileRateLimiter
Tests added: MethodNotAllowedTest (12), CorsMiddlewareTest (16), RateLimiterTest (15), FileRateLimiterTest (14), RateLimitMiddlewareTest (9), RouteCacheTest (15), RouteModelBindingTest (10)
Total: OK (180 tests, 261 assertions)
v0.2.4 and earlier
HTTP Request/Response, Router with groups and named routes, resource/apiResource, Pipeline, RouteRegistrar, RouteGroup, method override, $_GET isolation.