Download the PHP package webiny/event-manager without Composer

On this page you can find all versions of the php package webiny/event-manager. 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 event-manager

Event Manager Component

EventManager allows you to easily manage events throughout your application.

Install the component

The best way to install the component is using Composer.

For additional versions of the package, visit the Packagist page.

Usage

Accessing EventManager can be done in 2 ways. The preferable way is using EventManagerTrait, but you can also access it directly, using EventManager::getInstance(). Let's see a simple example of subscribing to an event called some.event with an instance of YourHandler:

You're done! You have just subscribed to an event and the moment some.event is fired, your handler will process it.

Event handlers

Now let's take a look at YourHandler. An event handler can be any class. EventManager will call handle(Event $event) method on your handler object, by default. You can, however, specify a method you want EventManager to call:

Besides using classes, you can also respond to an event using a callable:

Firing events

To fire a simple event use the following code:

You can also pass some data when firing an event, which will be passed to every event listener:

Any given data that is not an Event object, will be converted to generic Event object and your data will be accessible either by using array keys, or as object properties:

If you want to use custom Event data types, refer to section Custom event classes

Firing events using a wildcard

You can also use wildcard to fire multiple events at once. The following code will fire all events starting with event. and pass $data to each one of them:

Execution priority

EventManager allows you to specify an execution priority using priority() method. Here's an example:

After firing an event, the event listeners will be ordered by priority in descending order. The higher the priority, the sooner the listener will be executed. In this example, the order of execution will be as follows: secondCustomHandler, customHandler, thirdCustomHandler. Default priority is 101, so thirdCustomHandler is executed last.

Custom event classes

When firing events, you can also pass your own event classes, that extend generic Event class. For example, you want to fire an event called cms.page_saved and pass the Page object. Of course, you could simply pass an array like ['page' => $pageObject], but for the sake of the example, let's pretend it's more complicated than that:

This is a simple example, but it shows the power of creating your own Event classes and add as much functionality to your events as you need.

Event subscriber

Another cool feature of the EventManager is the ability to subscribe to multiple events at once. You will need to create a subscriber class implementing EventSubscriberInterface:

There are situations when you need to temporarily disable EventManager. For example, deleting a huge portion of files that are not directly related to the application (local cache files) does not require firing all of related events. In this case use the following methods:

Resources

To run unit tests, you need to use the following command:

$ cd path/to/Webiny/Component/EventManager/
$ composer.phar install
$ phpunit

All versions of event-manager with dependencies

PHP Build Version
Package Version
Requires php Version ^7
webiny/std-lib Version ~1.6
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 webiny/event-manager contains the following files

Loading the files please wait ....