Download the PHP package somnambulist/laravel-doctrine-domain-events without Composer

On this page you can find all versions of the php package somnambulist/laravel-doctrine-domain-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-doctrine-domain-events

Replaced with https://github.com/dave-redfern/somnambulist-domain

This project has been replaced with a generic domain library that combines several packages into one for easier maintenace.

Domain Events for Laravel-Doctrine ORM

Adds support for Domain Events to Doctrine entities. This package is inspired by and based on the Gist and blog posts by Benjamin Eberlei:

Requirements

Installation

Install using composer, or checkout / pull the files from github.com.

A service provider is included that adds compiles allowing the main classes to be added to the main bootstrap.

Raising Events

To raise an event, decide which actions should result in a domain event. These should coincide with state changes in the domain objects and the events should originate from your main entities (aggregate roots).

For example: you may want to raise an event when a new User entity is created or that a role was added to the user.

This does necessitate some changes to how you typically work with entities and Doctrine in that you should remove setters and nullable constructor arguments. Instead you will need to manage changes to you entity through specific methods, for example:

Internally, after updating the entity state, call: $this->raise(new NameOfEvent([])) and pass any specific parameters into the event that you want to make available to the listener. This could be the old vs new or the entire entity reference, it is entirely up to you.

public function __construct($id, $name, $another, $createdAt)
{
    $this->id        = $id;
    $this->name      = $name;
    $this->another   = $another;
    $this->createdAt = $createdAt;
    $this->raise(new MyEntityCreatedEvent(['id' => $id, 'name' => $name, 'another' => $another]));
}

Generally it is better to not raise events in the constructor but instead to use named constructors for primary object creation:

private function __construct($id, $name, $another, $createdAt)
{
    $this->id        = $id;
    $this->name      = $name;
    $this->another   = $another;
    $this->createdAt = $createdAt;
    $this->raise(new MyEntityCreatedEvent(['id' => $id, 'name' => $name, 'another' => $another]));
}

public static function create($id, $name, $another)
{
    $entity = new static($id, $name, $another, new DateTime());
    $entity->raise(new MyEntityCreatedEvent(['id' => $id, 'name' => $name, 'another' => $another]));

    return $entity;
}

Firing Domain Events

This implementation includes a Doctrine subscriber that will listen for entities that implement the RaisesDomainEvent interface and then ensures that releaseAndResetEvents() is called.

To use the included listener, add it to your list of event subscribers in the Doctrine configuration. This is per entity manager.

Creating a Domain Event Listener

Listeners can have their own dependencies (constructor is not defined), and are called after the onFlush Unit of Work event. The listener can perform any post processing as necessary, even triggering more events.

The listener should add methods that are named:

The example from the unit test:

class EventListener
{    
    public function onMyEntityCreated(MyEntityCreatedEvent $event)
    {
        printf(
            "New item created with id: %s, name: %s, another: %s",
            $event->getProperty('id'),
            $event->getProperty('name'),
            $event->getProperty('another')
        );
    }
}

The unit test shows how it can be implemented.

Be sure to read the posts by Benjamin Eberlei mentioned earlier and check out his Assertion library for low dependency entity validation.

Alternatively, for validation that hooks into the main Laravel validator see: Entity Validation for Laravel Doctrine.

Links


All versions of laravel-doctrine-domain-events with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
ext-bcmath Version *
illuminate/validation Version ~5.2
laravel-doctrine/orm Version 1.*
somnambulist/laravel-domain-input-mapper Version ~0.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package somnambulist/laravel-doctrine-domain-events contains the following files

Loading the files please wait ....