codesaur / http-application
PSR-7 & PSR-15 нийцсэн хөнгөн, уян хатан HTTP Application цөм
Requires
- codesaur/http-message: ^3.0.1
- codesaur/router: ^5.1.1
- psr/http-server-middleware: ^1.0.2
Requires (Dev)
- phpunit/phpunit: ^10.0
- dev-main
- v6.0.1
- v6.0.0
- v5.9.0
- v5.8.1
- v5.8.0
- v5.7.2
- v5.7.1
- v5.7.0
- v5.6.0
- v5.5.6
- v5.5.5
- v5.5.4
- v5.5.3
- v5.5.2
- v5.5.1
- v5.5.0
- v5.4.7
- v5.4.6
- v5.4.5
- v5.4.4
- v5.4.3
- v5.4.2
- v5.4.1
- v5.4.0
- v5.3.5
- v5.3.4
- v5.3.3
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.6
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.1.9
- v5.1.8
- v5.1.7
- v5.1.6
- v5.1.5
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1
- v5.0
- v4.7
- v4.6
- v4.5
- v4.4
- v4.3
- v4.2
- v4.1
- v4.0
- v3.1
- v3.0
- v2.5
- v2.4
- v2.3
- v2.2.1
- v2.2
- v2.1
- v2.0.2
- v2.0.1
- v2.0
- v1.2.1
- v1.2
- v1.1.2
- v1.1.1
- v1.1
- v1.0.2
- v1.0.1
- v1.0
This package is auto-updated.
Last update: 2026-03-06 02:56:12 UTC
README
PSR-7 & PSR-15 нийцсэн хөнгөн, уян хатан HTTP Application цөм Lightweight, flexible HTTP Application core compliant with PSR-7 & PSR-15
Агуулга / Table of Contents
- Монгол | 2. English | 3. Getting Started
1. Монгол тайлбар
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-үүдийн тайлбар
- Шалгалтын тайлан - Код шалгалтын тайлан
2. English Description
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.
Key Features
- 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
Documentation
- Full Documentation - Installation, usage, examples
- API Reference - Complete API documentation
- Review - Complete package review and code quality assessment
3. Getting Started
Requirements
- PHP 8.2.1+
- Composer
- PSR-7 compatible HTTP Message implementation (e.g.,
codesaur/http-message)
Installation
Composer ашиглан суулгана / Install via Composer:
composer require codesaur/http-application
Quick Examples
Application - Basic Setup
use 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);
Router - Dynamic Routes
// Төрөлтэй параметртэй нэртэй 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']; });
Controller - MVC Pattern
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"; } }
Middleware - PSR-15 & Closure
// 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; });
Running Tests
Тест ажиллуулах / 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:coverage
Architecture
Application
+-- Middleware stack (PSR-15 + Closure)
+-- Router (codesaur/router)
+-- ExceptionHandler
+-- Controller / Closure route executor
Request Flow: Application -> Middleware -> Match route -> Controller/action/Closure -> Response
Changelog
- CHANGELOG.md - Full version history
Contributing & Security
License
This project is licensed under the MIT License.
Author
Narankhuu
codesaur@gmail.com
https://github.com/codesaur
codesaur ecosystem: https://codesaur.net