PHPackages                             samsonphp/event - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. samsonphp/event

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

samsonphp/event
===============

SamsonPHP events module

1.0.6(11y ago)38.2k7Open Software License (OSL) v 3.0PHP

Since Nov 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/SamsonPHP/event)[ Packagist](https://packagist.org/packages/samsonphp/event)[ Docs](http://samsonos.com/)[ RSS](/packages/samsonphp-event/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (7)Used By (7)

\#SamsonPHP events module [![Latest Stable Version](https://camo.githubusercontent.com/2cff4def792402101f5ec7f058b705a55c5e54fc6ff0e5a89f643a582a7b5b81/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f6576656e742f762f737461626c652e737667)](https://packagist.org/packages/samsonphp/event)[![Build Status](https://camo.githubusercontent.com/7c7ffef10a0a76c5767c5845749c84c9b405c0f8b1c9e54aa61c86670e99b678/68747470733a2f2f7472617669732d63692e6f72672f53616d736f6e5048502f6576656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/SamsonPHP/event)[![Code Coverage](https://camo.githubusercontent.com/31132d600579e5d8477684f617a40c5659302b2adfa8619d7c59393b4e70253d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f53616d736f6e5048502f6576656e742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SamsonPHP/event/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/db2f0377b45cf99807c652d8f1c40c97a08badd92d2f679f8f20133ba89e651d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f6576656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/event/?branch=master)[![Stories in Ready](https://camo.githubusercontent.com/b0d455c7141ddce650ce0023e7c106870e38d71c192e1e2443f648bb28b8e16b/68747470733a2f2f62616467652e776166666c652e696f2f73616d736f6e7068702f6576656e742e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/samsonphp/event)[![Total Downloads](https://camo.githubusercontent.com/c1cba536bb9ef9557c021d820d3f71c0795ed3d6abcb27daf65c599035287da3/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f6576656e742f646f776e6c6f6164732e737667)](https://packagist.org/packages/samsonphp/event)

We have build unique and very simple approach to make our modules and classes very loosely coupled by creating event-driven logic. All core module code is build using this approach which gives unlimited abilities in extending its functionality and adding supeior features to it. This approach is build with programming pattern Observer in mind, but has a little bit different approach.

Events gives us opportunity to remove interclass connections, so it would be perfectly suited for writing unit tests. From other hand, before moving to event based system, we had a lot of different handler stack, every of them fulfilled only only specific goal and had to have field and function for working with it, with event approach we dont need all this stacks, functions and other stuff anymore.

Basics
------

[](#basics)

We have created one simple static class to provide all this awesome features in SamsonPHP, called `\samson\core\Event`. This class has two main simple static functions:

- `fire($id, $params)`
- `signal($id, $params)`
- `subscribe($id, $params)`

Event identifier
----------------

[](#event-identifier)

This is the main parameter which connects event subscribers and executors, identifier must match followings standard rules:

- must be in lowercase - as all identifiers is resolved only in lowercase
- must consist of this parts: `[module_name].[sub_module_name].[event_name]`
- event name, if it is long, must be separated with underscore('\_') All firing module, class events must specified in its documentation `Events` section

Event - Subscribe
-----------------

[](#event---subscribe)

This method is used to register listener for a specific event identifier, there is no actual validation or checking if this identifier will ever be fired somewhere, we actually do not know, but we hope, and our hopes would be fulfilled, as we can read module documentation and subscribe only for existing events. This is done so because we cannot guarantee what events will actually fire because code can be loaded in different order(thanks to autoloading) and sucbcribe() can be called much earlier then event declaration possibly be, so we have decided and putted this responsibility on developers shoulders and only they must think of what event they subscribe on.

Method declaration:

```
subscribe($key, $handler, $params = array())
```

- `$key` - Unique event identifier, read module documentation to find out which events and when will be fired.
- `$handler` - Callback, can be simple string `callme` if this is just a function or `array($obj, '[method_name]')` or `array('[classs_name]', '[method_name]')` for static methods.
- `$params` - Collection of additional data that is needed when the event handler will be excuted, this array will be passed ass callback arguments.

Every call to event subscription will return unique handler identifier for this unique event identifier, this identifier can be used to [unsubscribe](#event-unsubscribe) from event.

Event - Unsubscribe
-------------------

[](#event---unsubscribe)

If want to remove your event subscription for some reason you need to use event identifier and handler identifier: Method declaration:

```
unsubscribe($key, $identifier)
```

- `$key` - Unique event identifier, read module documentation to find out which events and when will be fired.
- `$identifier` - Unique event handler identifier, it is returned from [event subscribe](#event-subscribe) function call.

Event - Fire
------------

[](#event---fire)

This method is used to tell all other listeners(modules, classes) who has subscribed to current event identifier that its being happened right here and right now. When this method is triggered its meant that this is exact place and time when all subscribers must handle current event.

Method declaration:

```
function fire($key, $params = array())
```

- `$key` - Unique event identifier, who fires this event must specify it in the documentation.
- `$params` - Collection of additional data that will be passed to callback, this collection differs from the subscribe parameters collection as it is being send from event firing side.

We recommend to think twice before firing event somewhere in your code, as this must be realy needed and usefull event to avoid system overhead.

> When the actual event is trigered, system merges event fired params with subscribe parameters, event fired parameters is first to be passed to callback function. This is done in this way because there can be any amount of subscribers with different count of parameters, but the event firing parameters will never change.

Event - Signal
==============

[](#event---signal)

This is method is used to perform only LAST subscriber callback will be called and the result of it execution will be returned. This is done when this event must be handled only once. Method declaration:

```
function signal($key, $params = array())
```

All other logic is the same as [Event - Fire](#event-fire)

> For example events for routing system, you cannot use multiple routing systems in one application.

Changing data in subscribed event handlers
------------------------------------------

[](#changing-data-in-subscribed-event-handlers)

When you want to pass variable to event handler to change it just use array with references syntax:

```
Event::fire('core.routing', array(&$url, $count))
```

In the example described above we have passed a $url variable by reference to all possible subscribers to `core.routing` event, and if one of them will change it, it will be changed every where.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 86.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

6

Last Release

4134d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6510135856527278a1da14ea26ecaa3f016c27604236cec14ee550a8441dec52?d=identicon)[samsonphp](/maintainers/samsonphp)

---

Top Contributors

[![vitalyiegorov](https://avatars.githubusercontent.com/u/586558?v=4)](https://github.com/vitalyiegorov "vitalyiegorov (32 commits)")[![nik-os](https://avatars.githubusercontent.com/u/7326967?v=4)](https://github.com/nik-os "nik-os (5 commits)")

---

Tags

eventsamsonphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samsonphp-event/health.svg)

```
[![Health](https://phpackages.com/badges/samsonphp-event/health.svg)](https://phpackages.com/packages/samsonphp-event)
```

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[league/event

Event package

1.6k141.6M183](/packages/league-event)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[winzou/state-machine

A very lightweight yet powerful PHP state machine

52113.7M18](/packages/winzou-state-machine)[spatie/laravel-event-sourcing

The easiest way to get started with event sourcing in Laravel

9003.7M26](/packages/spatie-laravel-event-sourcing)[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.5M21](/packages/spatie-laravel-google-calendar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
