- Notifications
You must be signed in to change notification settings - Fork10
The Narration PHP Framework - Empowering everyone to build reliable and loosely coupled web apps.
License
narration/narration
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
THIS PACKAGE HASN'T BEEN RELEASED, DO NOT USE YET
This is a work in progress.
Narration is the source for modern PHP - It enforces the implementation of proven patterns to bring resilience, reliability, and coordination to your web application.
- DDD oriented code architecture
- Zero coupling to the framework
- Strong PHPStan rules to ensure the quality of the code
- ForScalable PSR-7 and PSR-15 compliant REST services.
RequiresPHP 7.1.3+
Create your project usingComposer:
composer create-project narration/narration blog --stability=dev --prefer-source
Then, serve the appplication athttp://127.0.0.1:8000/
:
php -S 127.0.0.1:8000 serve.php
The application logic is where you implement all use cases that depend on a given front end. It delegates the execution of business rules to the domain layer.Keep this layer thin.
HTTP request handlers are a fundamental part of any web application. Server-side code receives a request message, processes it, and produces a response message:
finalclass Index{/** * Handle the given request. * * @param \Psr\Http\Message\ServerRequestInterface $request * * @return array */publicfunction__invoke(ServerRequestInterface$request):array {return ['quote' =>'Intellectuals solve problems, geniuses prevent them.', ]; }}
Request handlersshould be placed atAppplication/Http/RequestHandlers
. The routes are defined within theconfig/routes/http.php
file.
This convention leads code that is easier to maintain, refactor and test.
An HTTP middleware component participates in processing an HTTP message. It acts on the request, generating the response, or forwarding the request to a subsequent middleware and possibly acting on its response. It provides a convenient mechanism for filtering HTTP requests entering your application:
finalclass TrimStringsimplements MiddlewareInterface{/** * Filters the given request before or after sending it to the handler. * * @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Server\RequestHandlerInterface $handler * * @return \Psr\Http\Message\ResponseInterface */publicfunctionprocess(ServerRequestInterface$request,RequestHandlerInterface$handler):ResponseInterface {foreach ($request->getAttributes()as$name =>$value) {if (is_string($value)) {$request =$request->withAttribute($name,trim($value)); } }return$handler->handle($request); }}
The middleware are defined within theconfig/routes/http.php
file.
We provide a simple, yet powerful, IOC container. The framework doesn’t couple you to our container, feel free to swap to another PSR-11 implementation on the ‘config/container.php’ file.
The container is used by the default PSR-7 router of the framework to inject the necessary dependencies on the request handlers.
An injector injects the dependencies of the application on the container. Theyshould be placed atAppplication/Injectors
.
Injectors are defined within theconfig/container.php
file.
Responsible for representing concepts of the business rules. This layer is theheart of business software.
The infrastructure layer is how the data that is initially held in domain entities (in memory) is persisted in databases or another persistent store. An example is using Doctrine code to implement the Repository pattern classes that use Entities topersist data in a relational database.
Thank you for considering to contribute to Narration. All the contribution guidelines are mentionedhere.
You can have a look at theCHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!:@enunomaduro
Do you like this project? Support it by donating
Lot of this readme is based onDesign a DDD-oriented microservice by Microsoft.
Narration is an open-sourced software licensed under theMIT license.