PHPackages                             architectnate/triggr-php - 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. architectnate/triggr-php

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

architectnate/triggr-php
========================

A simple event handler for php

v1.0(10y ago)143MITPHPPHP &gt;=5.4

Since Aug 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ArchitectNate/TriggrPHP)[ Packagist](https://packagist.org/packages/architectnate/triggr-php)[ Docs](https://github.com/thephpeffect/TriggrPHP)[ RSS](/packages/architectnate-triggr-php/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

TriggrPHP
=========

[](#triggrphp)

A lightweight PHP event handling system.

![Packagist](https://camo.githubusercontent.com/134e0cb69b191922720fb22b60d83d7a2d3bc7de05a953ab3736f08949ec1a7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172636869746563746e6174652f7472696767722d7068702e737667)[![Build Status](https://camo.githubusercontent.com/a3c47ad830c6e1305a6935120ed498c63099e9be6d8da5509bad47e2d5d79d12/68747470733a2f2f7472617669732d63692e6f72672f4172636869746563744e6174652f5472696767725048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ArchitectNate/TriggrPHP)[![Dependency Status](https://camo.githubusercontent.com/f0d61d38dfb6ac0d975f548287cbc6577cc290f7c9c23f3638f8940755f759fe/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537653531643731373938303666303032663461613266652f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/56b3ba5e0a0ff5002c85ed7b)[![codecov.io](https://camo.githubusercontent.com/6032ab6d80b95418459bcf04fa481527af0fe2b277dd26d54b180e1cc4d51a36/68747470733a2f2f636f6465636f762e696f2f6769746875622f6172636869746563746e6174652f5472696767725048502f636f7665726167652e737667)](https://codecov.io/github/architectnate/TriggrPHP)![Packagist](https://camo.githubusercontent.com/c54965ff802ad986deaea0c29aa2e6d905e795b0214a8877ff4ae522252ce85f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6172636869746563746e6174652f7472696767722d7068702e737667)

This system allows you to set events and event handlers, fire the events and control the event flow. This is a great way to enabled developers to add event hooks to software.

Note: This is not a replacement for major frameworks like ReactPHP, but more of a supplement tool for other frameworks and situations where event handling would be convenient.

Installation
============

[](#installation)

The recommended way to install Triggr is through composer(). Type the following command in your shell environment:

php ~/composer.phar require architectnate/triggr-php

Usage
=====

[](#usage)

#### Event Phrase

[](#event-phrase)

Using TriggrPHP requires the creation of event phrases. Essentially, an event phrase is an event name with or without a handler name in this format: EventName:HandlerName (or just EventName alone).

These event phrases are used create events. In the case where no handler name is given, one is automatically created. the developer has the option to include a handler name to make what they are doing more clear if they would like.

#### Firing Events

[](#firing-events)

When bulding out an application you would use the "fire" method to specify where you want actions to occur, such as a pre, or post save method on an Entity. The event phrase contains only the event name, all handlers on that event are fired.

```
Triggr::fire("EventName");
```

If you need to provide data to the event to be used by it's handlers, you may pass an array of arguments.

```
Triggr::fire("EventName", array($arg1, $arg2, $arg3));
```

In the case that it is needed to fire a specific handler on an event, the fireHandler method may be used. The event phrase this time must have both event name and handler name. Note that arguments are still available to be passed in.

```
Triggr::fireHandler("EventName:HandlerName", array($arg1));
```

#### Watching Events

[](#watching-events)

Once events are firing within your application you can "watch" them and perform actions when they fire. To do this, you will call the "watch" method. Every "watch" creates a handler. If you provide an event name or the full event phrase determines if TriggrPHP assigns a handler name for you, or not. It is not necessary to assign each handler it's own name, but it can be useful for more complex uses.

To simply watch an event, provide a name and an action. The action can be any callable, so class methods and procedural methods are all usable.

```
// With event name only
Triggr::watch("MyEvent", function(){ echo "Event has fired!"; });

// With full event phrase (nameing the handler ourselves)
Triggr::watch("MyEvent:FireMessage", function(){ echo "Event has fired!"; });
```

Watch actions may return data, the "fire" method will pass the data along. Since there may be multiple handlers per event, the returned data is provided in an array, sorted by the order that the handlers were run. Note: "fireHandler" returns mixed data, whatever the "watch" action returns, it returns since there is no potential for multiple handlers.

```
Triggr::watch("HelloWorld", function(){ return "Hello World"; });
$output = Triggr::fire("HelloWorld"); // Returns array("Hello World")
```

#### Options

[](#options)

When watching an event, options can be provided to the handler for a couple of reasons, to limit the number of times it can be run and to set a sort order or priority Defaults: RunLimit = 0, Priority = 100 (A run limit of 0 is infinite).

```
Triggr::watch("HelloWorld", function(){ return "Hello World"; }, array("RunLimit"=>1, "Priority"=>101));
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

3966d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea67c5dea44213d3f6797ebf8578f34483bfb7b9e4fd9766874fb1cf2794975e?d=identicon)[Asperon11](/maintainers/Asperon11)

---

Tags

phpeventlistener

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/architectnate-triggr-php/health.svg)

```
[![Health](https://phpackages.com/badges/architectnate-triggr-php/health.svg)](https://phpackages.com/packages/architectnate-triggr-php)
```

###  Alternatives

[supervisorphp/event

Listen to Supervisor events in PHP

1444.5k](/packages/supervisorphp-event)

PHPackages © 2026

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