Code Monkey home page Code Monkey logo

narration's Introduction

THIS PACKAGE HASN'T BEEN RELEASED, DO NOT USE YET

Build Status Quality Score Total Downloads Latest Version License

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.

Philosophies

  • DDD oriented code architecture
  • Zero coupling to the framework
  • Strong PHPStan rules to ensure the quality of the code
  • For Scalable PSR-7 and PSR-15 compliant REST services.

Quick start

Requires PHP 7.1.3+

Create your project using Composer:

composer create-project narration/narration blog --stability=dev --prefer-source

Then, serve the appplication at http://127.0.0.1:8000/:

php -S 127.0.0.1:8000 serve.php

Structure

Application

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.

Application > Http > Request Handlers

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:

final class Index
{
    /**
     * Handle the given request.
     *
     * @param  \Psr\Http\Message\ServerRequestInterface $request
     *
     * @return array
     */
    public function __invoke(ServerRequestInterface $request): array
    {
        return [
            'quote' => 'Intellectuals solve problems, geniuses prevent them.',
        ];
    }
}

Request handlers should be placed at Appplication/Http/RequestHandlers. The routes are defined within the config/routes/http.php file.

This convention leads code that is easier to maintain, refactor and test.

Application > Http > Middleware

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:

final class TrimStrings implements 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
     */
    public function process(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 the config/routes/http.php file.

Application > Injectors

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. They should be placed at Appplication/Injectors.

Injectors are defined within the config/container.php file.

Domain

Responsible for representing concepts of the business rules. This layer is the heart of business software.

Infrastructure

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 to persist data in a relational database.

Contributing

Thank you for considering to contribute to Narration. All the contribution guidelines are mentioned here.

You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: @enunomaduro

Support the development

Do you like this project? Support it by donating

Credits

Lot of this readme is based on Design a DDD-oriented microservice by Microsoft.

License

Narration is an open-sourced software licensed under the MIT license.

narration's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

narration's Issues

RFC: Service Providers

Hey @nunomaduro ,

Congrats with starting your own framework!

I saw you are trying to achieve zero coupling (I love that!).
To do this, you are relying on PSR-11 for containers. This is a good thing, but eventually, you will run into some issues. Swapping containers is not that easy as it requires to reconfigure the containers from the ground up.

If you don't know me, I'm the co-editor of PSR-11. I take a lot of interest in container interoperability and I'm currently working on the next container-related PSR that is about service providers (or injectors).

I saw you are already using "injectors". I'm trying to standardize those. Take a look at https://github.com/container-interop/service-provider/

The whole idea would be to have standard injectors/service-providers that can be used with any containers. That would make a standard bundle/module system possible. This is much needed because even if you manage to write a wonderful framework, it will take a huge amount of time and energy before you can have the same number of bundles / service-providers as Symfony or Laravel. On the other end, if we could standardize the service-providers, we could share those amongst frameworks.

I've had a look at the injectors you are using. They are quite close to what container-interop/service-provider so adding support for this could be quite easy. In return, you could use any of the service providers already written: https://packagist.org/packages/container-interop/service-provider/dependents

What do you think?

Logo needed

I'm looking for someone to come up with a nice logo for this framework. Can you help? 💖

Website domain

Looks like we are going for narrationphp.com. What do you guys think?

RFC: Database

Should we provide a default database layer? If yes, what and how?

Website needed

I'm looking for someone to come up with a nice website for this framework. Can you help? 💖

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.