PHPackages                             gburtini/hooks - 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. gburtini/hooks

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

gburtini/hooks
==============

Hooks, plugins, filters, event-driven programming, plugin architecture all in a clean easy interface.

0.1.5(11y ago)15175[2 issues](https://github.com/gburtini/PHP-Hooks-System/issues)GPLPHPPHP &gt;=5.4.0

Since Mar 31Pushed 10y ago5 watchersCompare

[ Source](https://github.com/gburtini/PHP-Hooks-System)[ Packagist](https://packagist.org/packages/gburtini/hooks)[ Docs](http://github.com/gburtini/PHP-Hooks-System)[ RSS](/packages/gburtini-hooks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (8)Used By (0)

PHP Hooks and Filters System
============================

[](#php-hooks-and-filters-system)

*Event-driven programming, a plugin architecture, hooks, filters, all wrapped in to a simple, efficient and clean Composer-ready interface.*

This is an elegant way of coding plugin architectures or other decoupled software solutions. The class provides three major methods: bind, run and filter; combined, these allow you to integrate in to existing systems without interfering with their existing code.

There's also a plugin loader in `Plugins.php` which can be used to load a directory of optional code. Use is simple: `Plugins::load("directory")` will traverse the directory and load all non-disabled (~, . prefix) folders containing a `init.php` file.

Installation
------------

[](#installation)

Everything you need is contained within the single file `Hooks.php`, but the most convenient way to install is with composer:

```
composer require gburtini/hooks

```

Usage
-----

[](#usage)

- `bind(string $hook, callback $callback, int $priority)` - binds a callback to a hook
- `run(string $hook, array $parameters)` - executes all the functions bound to a given hook
- `filter(string $hook, object $value, array $parameters)` - executes all the functions bound to a given hook, passing in $value each time, and finally return the value

The designed use case is that throughout your existing software, you will call `Hooks::filter` and `Hooks::run` where you want to allow users to hook with a specified `$hook` value. Then users can call `Hooks::bind()` anytime before your code runs to associate code with the various locations -- filters will return the value (so that a function can change it) and run calls will simply run functions with no in-code side effects.

Debugging
---------

[](#debugging)

The Hooks class has a debug level setting which produces some output indicating which hooks are running and when. Call `Hooks::setDebugLevel($debug_level)` at runtime to set the debug output. `$debug_level` can take on the following values:

- `Hooks::DEBUG_NONE` - the default, no debug output.
- `Hooks::DEBUG_EVENTS` - a list of the `::run` and `::filter` calls as they happen.
- `Hooks::DEBUG_CALLS` - a list of every callback executed in each hoo/filter.
- `Hooks::DEBUG_BINDS` - a list of each time a bind is setup for a hook or filter.
- `Hooks::DEBUG_INTERACTION` - outputs every call to a class method (bind, run, filter, and the private methods)
- `Hooks::DEBUG_ALL` - all of the above combined.

You can also combine these with the bitwise OR, for example `Hooks::DEBUG_EVENTS | Hooks::DEBUG_BINDS` outputs all the run/filter/bind calls as they happen.

Future Work
-----------

[](#future-work)

A nice future feature would be to enforce some sort of constraints on what these binds can do -- allowing "untrusted" (in the sense of the data) code to run in some sort of quasi-sandbox; for example, the filters could check to ensure the value was constrained to a particular type, range or callback validation.

Timing functionality for the debug code to see which hooks and associated callbacks are slow is an interesting angle here too.

Sorting can be called less frequently. If nothing has changed, it is unnecessary to call the sort function again. That said, the used quicksort variant should be rapid on already sorted data.

License
-------

[](#license)

*Copyright (C) 2012-2015 Giuseppe Burtini*

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~1 days

Total

7

Last Release

4056d ago

PHP version history (2 changes)0.0.0PHP &gt;=5.0.0

0.1.0PHP &gt;=5.4.0

### Community

Maintainers

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

---

Top Contributors

[![gburtini](https://avatars.githubusercontent.com/u/780031?v=4)](https://github.com/gburtini "gburtini (12 commits)")[![raruler](https://avatars.githubusercontent.com/u/12248?v=4)](https://github.com/raruler "raruler (1 commits)")

---

Tags

eventplugineventsfilterhookspluginsHOOKfiltersevent-driven programming

### Embed Badge

![Health badge](/badges/gburtini-hooks/health.svg)

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

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)[zumba/symbiosis

Symbiosis, event structure for bootstrapping plugins.

1360.4k1](/packages/zumba-symbiosis)[bainternet/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

27621.3k2](/packages/bainternet-php-hooks)[millat/laravel-hooks

The WordPress filter, action system in Laravel

5715.1k](/packages/millat-laravel-hooks)[balbuf/composer-wp

Manage WordPress core, plugins, and themes with composer.

173.6k](/packages/balbuf-composer-wp)

PHPackages © 2026

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