alvinios/miel
最新稳定版本:1.0.0
Composer 安装命令:
composer require alvinios/miel
包简介
Object-oriented Web Micro Framework
README 文档
README
About The Project
Miel is an object-oriented PHP web development micro-framework (MIEL stands for Micro + Elegant, it also means "honey" in French). It' intend is to be designed based on elegant objects principles of Yegor Bugayenko. It means :
- No mutable classes
- No
nulls - No type-checking or reflexion
- No
publicstaticmethods orconstants - No configuration files
- No DI container
It was inspired by the framework Takes For being operational it requires PSR-7 and PSR-17 implementations/libraries of your choice. For example Guzzle PSR-7
Getting Started
composer require alvinios/miel
Quick Start
Create this index.php file:
use Alvinios\Miel\App; use Alvinios\Miel\Http\Emit; use Alvinios\Miel\Response\Text; use Alvinios\Miel\Fork\Regex; use GuzzleHttp\Psr7\{HttpFactory, ServerRequest}; (new Emit())( (new App( new Regex('/', new Text('Hello world!')) ))->response(ServerRequest::fromGlobals(), new HttpFactory(), new HttpFactory()) );
Cd to your index.php folder and run php local server
php -S localhost:8000
A Bigger Example
use Alvinios\Miel\App; use Alvinios\Miel\Http\Emit; use Alvinios\Miel\Endpoint\Base; use Alvinios\Miel\Request\WithRegex; use Alvinios\Miel\Response\{Json, Response, Text, Twig}; use Alvinios\Miel\Fork\{Regex, Methods}; use GuzzleHttp\Psr7\{HttpFactory, ServerRequest}; use Psr\Http\Message\ServerRequestInterface; (new Emit())( (new App( new Regex('/', new Text('Hello world!')), new Regex( '/users/(?P<id>[\d]+)', new Methods( ['post'], new class() extends Base { public function act(ServerRequestInterface $request): Response { return new Json( json_decode($request->getBody()->getContents()) ); } } ), new Methods( ['get'], new class() extends Base { public function act(ServerRequestInterface|WithRegex $request): Response { return new Text(sprintf( '<html><body>User %s</body></html>', $request->regex()->group('id') )); } } ) ) ))->response(ServerRequest::fromGlobals(), new HttpFactory(), new HttpFactory()) );
Generators
Routes can be composed as variadic argument of Routes or with Generators using Append wrapper.
use Alvinios\Miel\App; use Alvinios\Miel\Response\{Text, Twig}; use Alvinios\Miel\Fork\{Append, Regex}; new App( new Append( call_user_func(function() : \Iterator { yield new Regex('^(/|/home)$', new Twig($this->twig, 'index.html.twig', [])); }), call_user_func(function() : \Iterator { yield new Regex('/foo', new Text('Foo')); yield new Regex('/bar', new Text('Bar')); }) ) )
Middleware Support
You can shield a route/routes behind PSR-15 Middleware(s). This is how it can be done:
Multiple Middlewares
use Alvinios\Miel\Fork\{Regex, Shields}; use Psr\Http\Server\MiddlewareInterface; new Shields( new Regex('/foo', new Text('Behind middleware')), new class() implements MiddlewareInterface { ... }, new class() implements MiddlewareInterface { ... } )
Shields can be nested.
Single Middleware
use Alvinios\Miel\Fork\Shield; use Psr\Http\Server\MiddlewareInterface; new Shield( new class() implements MiddlewareInterface { ... }, new Regex('/foo', new Text('Behind middleware')) )
Note
Today the project is in a conceptual state and has not been tested in production environment.
License
Distributed under the MIT License. See LICENSE.txt for more information.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-14