Download the PHP package socarrat/events without Composer

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

Socarrat Events

The Socarrat event library contains the base for your event dispatchers. It aims to be quick and simple, as well as flexible and extensible at the same time.

Installation

You can install this package through Composer by running composer require socarrat/events. The library will be available under the Socarrat\Events namespace.

Concept

The thing this package is all about, are events.

Imagine you're on a little boat at open sea, and you have no idea where you are. Luckily, you have some flares. They have been seen by a nearby ship, and you're rescued.

This getting-lost is the mehaphor for an event: some kind of situation arises. When you lightened the flares, you fired or dispatched the event. Thanks to hooks or event listeners that have been set, the smoke has been noticed. The action (rescue) is executed when the callback of the event listener (the person who had saw you calling for help) is executed.

Usage

Creating an event

In order to create an event, you need to extend the abstract Event class. It's important that you override the $listeners property.

For example:

Nothing more is needed! Of course, you can extend the event to have custom methods and properties.

Listening to the event

To register an event listener, you have to call the on method. The closure is called every time the event is dispatched.

The first parameter is the sort order. Hooks with a lower order are called earlier. This method returns the index that has been assigned to the hook. It may be higher than the index you provided. In that case, the previous index/es were alreaty occupied.

Dispatching the event

Call the dispatch method to dispatch an event:

The parameters you pass to this method are passed to all event listeners, so that you can provide context-specific information.

API

abstract class Socarrat\Events\Event

static protected $listeners

An array of event listeners (closures) to call when the event is dispatched.

It's important that you override this in your own implementation!

static function getName(): string

Returns the name of the event.

static function on(int $priority, $callback): int

Registers an event listener for the current event. Returns the index that has been assigned to the listener.

Parameter name Type Default value Description
$priority int - The priority of this listener.
$callback closure - The function to execute when the event is fired.

static function dispatch(...$callbackData)

Dispatches the event. This executes all registered callbacks in order, passing optional callback data to them.

Warning: this is a blocking function; it will stop execution until all callbacks have finished. Callbacks are executed synchronously.

Parameter name Type Default value Description
...$callbackData mixed - Data to pass to the callbacks. Optional.

Copyright

(c) 2023 Romein van Buren. Licensed under the MIT license.

For the full copyright and license information, please view the license.md file that was distributed with this source code.


All versions of events with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
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 socarrat/events contains the following files

Loading the files please wait ....