PSR-7 & PSR-15 нийцсэн хөнгөн, уян хатан HTTP Application цөм Lightweight, flexible HTTP Application core compliant with PSR-7 & PSR-15
- Монгол | 2. English | 3. Getting Started
codesaur/http-application нь PSR-7 (HTTP Message) ба PSR-15 (HTTP Server RequestHandler/Middleware) стандартууд дээр суурилсан минималист, өндөр уян хатан, middleware суурьтай Application цөм юм.
Та хүсвэл:
- Router нэмэх
- Middleware удирдах
- Controller/action ашиглах
- Closure route ашиглах
- Exception handler бүртгэх
- Custom request attributes ашиглах
гэх мэтээр өөрийн хүссэн бүтэцтэй web application-ийг хэдхэн мөр кодоор босгох боломжтой.
- PSR-7 стандартын ServerRequest + Response
- PSR-15 Middleware & RequestHandler гинжин бүтэц
- Уян хатан Router интеграци (codesaur/router)
- Controller суурь класс (MVC хэв маяг дэмжлэг)
- Exception Handler (development mode-той)
- Хэт хөнгөн, хурдан
- Бүрэн танилцуулга - Суурилуулалт, хэрэглээ, жишээнүүд
- API тайлбар - Бүх метод, exception-үүдийн тайлбар
- Шалгалтын тайлан - Код шалгалтын тайлан
codesaur/http-application is a minimalist, highly flexible, middleware-based Application core built on PSR-7 (HTTP Message) and PSR-15 (HTTP Server RequestHandler/Middleware) standards.
You can:
- Add Router
- Manage Middleware
- Use Controller/action
- Use Closure routes
- Register Exception handler
- Use Custom request attributes
and build your desired web application structure with just a few lines of code.
- PSR-7 Standard ServerRequest + Response
- PSR-15 Middleware & RequestHandler Chain Structure
- Flexible Router Integration (codesaur/router)
- Controller Base Class (MVC pattern support)
- Exception Handler (with development mode)
- Extremely Lightweight and Fast
- Full Documentation - Installation, usage, examples
- API Reference - Complete API documentation
- Review - Complete package review and code quality assessment
- PHP 8.2.1+
- Composer
- PSR-7 compatible HTTP Message implementation (e.g.,
codesaur/http-message)
Composer ашиглан суулгана / Install via Composer:
composer require codesaur/http-applicationuse codesaur\Http\Application\Application;
use codesaur\Http\Application\ExceptionHandler;
use codesaur\Http\Message\ServerRequest;
// Application instance үүсгэх / Create Application instance
$app = new Application();
// Exception handler бүртгэх / Register exception handler
$app->use(new ExceptionHandler());
// Route бүртгэх / Register route
$app->GET('/', function ($req) {
echo 'Hello World!';
});
// Хүсэлт боловсруулах / Handle request
$request = (new ServerRequest())->initFromGlobal();
$response = $app->handle($request);// Төрөлтэй параметртэй нэртэй route / Named route with typed parameters
$app->GET('/user/{int:id}', [UserController::class, 'show'])->name('user.show');
// Олон method-тэй route / Multi-method route
$app->POST_PUT('/api/users', [UserController::class, 'save']);
// Параметртэй Closure route / Closure route with parameters
$app->GET('/sum/{int:a}/{uint:b}', function ($req) {
$params = $req->getAttribute('params');
echo $params['a'] + $params['b'];
});use codesaur\Http\Application\Controller;
class UserController extends Controller
{
public function show(int $id): void
{
$query = $this->getQueryParams();
$page = $query['page'] ?? 1;
echo "User ID: $id, Page: $page";
}
public function create(): void
{
$data = $this->getParsedBody();
$name = $data['name'] ?? 'Unknown';
echo "Created user: $name";
}
}// PSR-15 Middleware
class AuthMiddleware implements MiddlewareInterface
{
public function process($req, $handler): ResponseInterface
{
// Баталгаажуулалт шалгах / Check authentication
if (!$this->isAuthenticated($req)) {
return new Response(401);
}
return $handler->handle($req);
}
}
$app->use(new AuthMiddleware());
// Closure Middleware
$app->use(function ($req, $handler) {
$startTime = microtime(true);
$response = $handler->handle($req);
$duration = microtime(true) - $startTime;
error_log("Request took: {$duration}s");
return $response;
});Тест ажиллуулах / Run tests:
# Бүх тестүүдийг ажиллуулах / Run all tests
composer test
# Зөвхөн unit тест / Unit tests only
composer test:unit
# Зөвхөн integration тест / Integration tests only
composer test:integration
# Coverage-тэй тест ажиллуулах / Run tests with coverage
composer test:coverageApplication
+-- Middleware stack (PSR-15 + Closure)
+-- Router (codesaur/router)
+-- ExceptionHandler
+-- Controller / Closure route executor
Request Flow: Application -> Middleware -> Match route -> Controller/action/Closure -> Response
- CHANGELOG.md - Full version history
This project is licensed under the MIT License.
Narankhuu
codesaur@gmail.com
https://github.com/codesaur
codesaur ecosystem: https://codesaur.net