Download the PHP package mattferris/events without Composer

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

events

Build Status SensioLabsInsight

This is an events library with an included event logger. It's built with Udi Dahan's Domain Events pattern in mind.

Event Handling

Implementation starts with creating a DomainEvents class in your domain that extends MattFerris\Events\AbstractDomainEvents.

Then you can create individual event classes either by extending MattFerris\Events\Event or implementing MattFerris\Events\EventInterface. Event is an empty class so your event class will still need to provide it's own logic.

To raise/dispatch an event from within your domain entities, call DomainEvents::dispatch().

At the moment, there is no dispatcher configured so the event won't be handled by anything. Configuring a dispatcher can be done like so:

And now you can add events listeners to the dispatcher. Listeners can be any callable, and can listen for a specific event or pattern matched event. To match a specific event, use the fully qualified class name.

It's also possible to listen for events based on a prefix or suffix.

Finally, you can listen for all events using an asterisk.

Event Names

For flexiblity, listeners can also be assigned to listen for arbitrary event names. An event name can be passed to the dispatch method when the event is dispatched.

Listener Priority

By default, all listeners are given the same priority, and are called based on the order they were added. Listeners can also be assigned a priority to ensure they are called sooner or later then other listeners. The priority is an integer that is passed when adding the listener. 0 is the highest priority.

Priorities can also be assigned using the priority constants:

Event Providers

Events can be added using providers. Simply create a class that implements MattFerris\Provider\ProviderInterface and create a method called provides(). When passed to the register() method on the dispatcher, the provides() method will be passed an instance of the dispatcher, and you can then add listeners.

Event Logging

Event logging is accomplished by using MattFerris\Events\Logger. The constructor takes an instance of Dispatcher and a callable that is passed the resulting log message and can then write it to a log file, stderr, etc.

That's it! All dispatched events will be logged to PHP's error log. By default, log messages are just the name of the event prefixed with event:. For example:

You can change the prefix using setPrefix().

You can use logging helpers to customize the messages for certain events. Create a class in your domain called DomainEventLoggerHelpers and have it extend MattFerris\Events\AbstractDomainEventLoggerHelpers. Then simply create static methods to be called for domain events, where each method returns the string to be logged. These methods should start with on followed by the event name e.g. onSomeEvent.

To register the helpers with the logger:

Now, when SomeEvent is dispatched, the above helper will be called and the returned string will be logged.

In my opinion, it makes sense to have these logging helpers defined in MyDomain\DomainEventLoggerHelpers as the helpers are directly related to the events in the domain. When domain events are updated, the logging helpers can be updated and committed all together.


All versions of events with dependencies

PHP Build Version
Package Version
Requires mattferris/provider Version ~0.3
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 mattferris/events contains the following files

Loading the files please wait ....