Awesome Open Source
Awesome Open Source

Message Driven PHP

Build Status Code Coverage

MsgPHP is a project that aims to provide reusable domain layers for your application. It has a low development time overhead and avoids being overly opinionated.

It follows Semantic Versioning, yet during development phase a package can be marked @experimental to indicate "BC breaks" could be introduced.

Domain Layers

The domain layer is a collection of entity objects and related business logic that is designed to represent the enterprise business model. The major scope of this layer is to create a standardized and federated set of objects, that could be potentially reused within different projects. (source)

Currently supported domain layers are:

On the roadmap are:

  • Organization
  • File
  • Taxonomy
  • ...

Design-Time Considerations

  • The base domain package (msgphp/domain) integrates with YOUR domain layer (it's dependency free by design)
  • You inherit from the default domain layers, if used
  • The first-class supported ORM is Doctrine ORM
  • The first-class supported message bus is Symfony Messenger

Message Based

Each domain layer provides a set of messages to consume it. Typically the messages are categorized into command-, event- and query-messages.

The main advantage is we can intuitively create an independent flow of business logic. It provides consistency in handling our business logic by dispatching the same message in e.g. web as well as CLI.

$anyMessageBus->dispatch(new CreateSomething(['field' => 'value']));

A command-message is dispatched and picked up by its handler to do the work. This handler on itself dispatches a new event-message (e.g. SomethingCreated) to notify the work is done.

A custom handler can subscribe to the SomethingCreated event to further finalize the business requirements (e.g. dispatch another commmand-message).

class MakeSomethingWork
{
    private $bus;

    public function __construct(YourFavoriteBus $bus)
    {
        $this->bus = $bus;
    }

    public function __invoke(SomethingCreated $event)
    {
        // do work, or better delegate work:
        $this->bus->dispatch(new LetSomethingWork($event->something));
    }
}

Documentation

Contributing

See CONTRIBUTING.md



Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Php (293,349
Command Line (131,699
Security (32,121
Symfony (10,678
Twig (3,400
Uuid (3,120
Doctrine Orm (2,785
Reusable (2,629
Domain Driven Design (2,567
Cqrs (1,938
Symfony Bundle (1,629
Event Sourcing (1,130
User Management (661
Api Platform (96
Message Driven (30
Domain Model (24
Eav (16
Entity Attribute Value (5
Rich Domain (5