PHP class that manages a list of callbacks

0.1.1 2020-12-06 22:00 UTC

This package is auto-updated.

Last update: 2024-03-29 04:25:51 UTC


Build Status Scrutinizer Code Quality

Latest Stable Version License Monthly Downloads

GitHub Code Size GitHub Last Commit GitHub Activity GitHub Issues

This micropackage provides a simple class for managing a list of callbacks.


> composer require sminnee/callbacklist
use Sminnee\CallbackList\CallbackList;

$list = new CallbackList;
$list->add(function() { "this will get called"; });
$list->add(function() { "so will this"; });

// Or you can use it as a callable if you prefer

Arguments can be passed:

$list->add(function($greeting) { "$greeting, world!"; });

Return values are collated as an array

use Sminnee\CallbackList\CallbackList;

$list = new CallbackList;
$list->add(function() { return "this will get returned"; });
$list->add(function() { return "so will this"; });

// ["this will get returned", "so will this"]

Existing callbacks can be manipulated:

// Clear the list

// Or add a callback with a name
$list->add(function($greeting) { "$greeting, world!"; }, 'greeter');

// And then remove by that name

And you can inspect the content of the list:

// Return a single named callback

// Return everything as an array