Download the PHP package merkeleon/laravel-transactional-events without Composer

On this page you can find all versions of the php package merkeleon/laravel-transactional-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-transactional-events

Transaction-aware Event Dispatcher for Laravel (and Lumen)

This package introduces a transactional layer to the Laravel Event Dispatcher. Its purpose is to ensure, without changing a single line of code, consistency between events dispatched and database transactions. This behavior is also applicable to Eloquent events, such as saved and created.

Introduction

Let's start with a simple example of ordering tickets. Assume that it involves database changes and a payment registration and that the custom event OrderWasProcessed is dispatched immediately after the order is processed in the database.

The transaction in the above example may fail for several reasons: an exception may occur in the orderTickets method or in the payment service or simply due to a deadlock.

A failure will rollback the database changes made during the transaction. However, this is not true for the OrderWasProcessed event, which is actually dispatched and eventually executed. Considering that this event may result in sending an e-mail with the order confirmation, managing it the right way becomes mandatory.

The purpose of this package is to actually dispatch events if and only if the transaction in which they were dispatched commits. For instance, in the above example the OrderWasProcessed event would not be dispatched if the transaction fails.

Please note that events dispatched out of transactions will bypass the transactional layer, meaning that they will be handled by the default Event Dispatcher. This is true also for events in which the $halt parameter is set to true.

Installation

Laravel Package
5.8.x 1.0.x

Laravel

The installation of this package in Laravel is automatic thanks to the Package Auto-Discovery feature of Laravel 5.5+. Just add this package to the composer.json file and it will be ready for your application.

A configuration file is also available for this package. Run the following command to copy the provided configuration file transactional-events.php your config folder.

Lumen

As Lumen is built on top of Laravel packages, this package should also work smoothly on this micro-web framework. Run the following command to install this package:

In order to configure the behavior of this package, copy the configuration files:

Then, in bootstrap/app.php, register the configuration and the service provider:
Note: This package must be registered after the default EventServiceProvider, so your event listeners are not overriden.

Usage

The transactional layer is enabled by default for the events placed under the App\Events namespace.

However, the easiest way to make your events behave as transactional events is by implementing the contract Merkeleon\Events\Contracts\TransactionalEvent.
Note that events that implement it will behave as transactional events even when excluded in config.

As this package does not require any changes in your code, you are still able to use the Event facade and call the event() or broadcast() helper to dispatch an event:

Even if you are using queues, they will still work smothly because this package does not change the core behavior of the event dispatcher. They will be enqueued as soon as the active transaction succeeds. Otherwise, they will be discarded.

Reminder: Events are considered transactional when they are dispatched within transactions. When an event is dispatched out of transactions, it bypasses the transactional layer.

Configuration

The following keys are present in the configuration file:

Enable or disable the transactional behavior by changing the following property:

By default, the transactional behavior will be applied to events on App\Events namespace. Feel free to use patterns and namespaces.

Choose the events that should always bypass the transactional layer, i.e., should be handled by the default event dispatcher. By default, all *ed Eloquent events are excluded.

Known issues

Transactional events are not dispatched in tests.

This issue is fixed for Laravel 5.6.16+ (see #23832).
For previous versions, it is associated with the RefreshDatabase trait, namely when it uses database transactions to reset database after each test. This package relies on events dispached when transactions begin/commit/rollback and as each is executed within a transaction that rollbacks when test finishes, the dispatched application events are never actually dispatched. In order to get the expected behavior, use the Merkeleon\Testing\RefreshDatabase trait in your tests instead of the one originally provided by Laravel.

License

This package is open-sourced software licensed under the MIT license.


All versions of laravel-transactional-events with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ~5.8.0|6.*|7.*|8.*|9.*|10.*|11.*
illuminate/events Version ~5.8.0|6.*|7.*|8.*|9.*|10.*|11.*
illuminate/support Version ~5.8.0|6.*|7.*|8.*|9.*|10.*|11.*
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 merkeleon/laravel-transactional-events contains the following files

Loading the files please wait ....