PHPackages                             symplely/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. [API Development](/categories/api)
4. /
5. symplely/hooks

ActiveLibrary[API Development](/categories/api)

symplely/hooks
==============

A simple event dispatching plugin library, a ported fork of WordPress hook API system.

1.0.0(6y ago)43MITPHPPHP &gt;7.1

Since Nov 22Pushed 6y ago1 watchersCompare

[ Source](https://github.com/symplely/hooks)[ Packagist](https://packagist.org/packages/symplely/hooks)[ RSS](/packages/symplely-hooks/feed)WikiDiscussions master Synced 1w ago

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

hooks
=====

[](#hooks)

[![Build Status](https://camo.githubusercontent.com/474639152adcc0cd1e6e60da455ad6d77821b38c867a73b2df7664b5ac08b40b/68747470733a2f2f7472617669732d63692e6f72672f73796d706c656c792f686f6f6b732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/symplely/hooks)[![Build status](https://camo.githubusercontent.com/79c1f8c5c9d236d7cef7f229b8313bb18eeefb31abfc06ef42c1026652329acc/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f78666a3574367735703467323866366e2f6272616e63682f6d61737465723f7376673d74727565)](https://ci.appveyor.com/project/techno-express/hooks/branch/master)[![codecov](https://camo.githubusercontent.com/e043b3b7674a100aa42f62ef6571be224175b7eed9d28dba54cbd0709f249e4d/68747470733a2f2f636f6465636f762e696f2f67682f73796d706c656c792f686f6f6b732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/symplely/hooks)[![Codacy Badge](https://camo.githubusercontent.com/9df764d563b5e7d4884e8260d5cc07c40f64cf75513e43aa611f4ff07bbe63b6/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6430613861373832656661303463616138393536633634363236633863346237)](https://www.codacy.com/manual/techno-express/hooks?utm_source=github.com&utm_medium=referral&utm_content=symplely/hooks&utm_campaign=Badge_Grade)[![Maintainability](https://camo.githubusercontent.com/2d90a50faf4c246cb3445d4acafb4ca74b5aac844214a4bb26eacb8f100d102b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f65376236313339653237373833633363346165302f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/symplely/hooks/maintainability)

This library allows you to easily add some event-based architecture into your application thru registering call-backs that would be executed by triggering a **hook**, **event**, or **listener** on a string identifier/tag, which we call here **$hook\_point**, which would normally be expressing desired action with prefixes like "before" or "after" if necessary.

---

How to Use?

Simple, Include the class file in your application bootstrap (setup/load/configuration or whatever you call it) and start hooking your filter and action hooks using the global `Hooks` functions. Ex:

```
add_action('header_action', 'echo_this_in_header');

function echo_this_in_header() {
   echo 'this came from a hooked function';
}
```

then all that is left for you is to call the hooked function when you want anywhere in your application, EX:

```
echo '';
  do_action('header_action');
echo '';
```

and you output will be:

```
this came from a hooked function
```

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

[](#installation)

To install this library make sure you have [composer](https://getcomposer.org/) installed, then run following command:

```
composer require symplely/hooks
```

Usage
-----

[](#usage)

This library is inspired by the EventEmitter API found in [node.js](https://github.com/nodejs/node/blob/master/lib/events.js), and [Événement](https://github.com/igorw/evenement).

So it comes with a familiar simple event emitter interface that delegates to the `add_filter`, `apply_filters`, `add_action` and `do_action` methods of the `Hooks` API class.

### Creating an Emitter

[](#creating-an-emitter)

```
