2017 © Pedro Peláez
 

library rock-events

A simple implementation of Pub/Sub for PHP

image

romeoz/rock-events

A simple implementation of Pub/Sub for PHP

  • Friday, November 6, 2015
  • by romeOz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4,367 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Implementation of Publisher-Subscriber for PHP

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License, (*1)

Features

  • Handler can be a closure, instance, and static class
  • Standalone module/component for Rock Framework

Installation

From the Command Line:, (*2)

composer require romeoz/rock-events

In your composer.json:, (*3)

{
    "require": {
        "romeoz/rock-events": "*"
    }
}

Quick Start

use rock\events\Event;

class Foo 
{
    public $str = 'Rock!';
}

$object = new Foo();
$eventName = 'onAfter';
$handler = function (Event $event) {
    echo "Hello {$event->owner->str}"; 
};

Event::on($object, $eventName, $handler);

Event::trigger($object,  'onAfter'); // output: Hello Rock!

Documentation

on(string|object $class, string $name, callable $handler)

To subscribe to the event., (*4)

Set a handler can be as follows:, (*5)

$handler = function (Event $event) { 
    echo "Hello Rock!"; 
};
Event::on(new Foo, 'onAfter', $handler);

Options:, (*6)

  • function (Event $event) { ... }
  • [new Foo, 'method']
  • ['Foo', 'static_method']

trigger(string|object $class, string $name, Event $event = null)

To publish event., (*7)

Event::trigger(new Foo,  'onEvent'); 

// or

Event::trigger('test\Foo',  'onEvent');

off(string|object $class, string $name, callable $handler = null)

Detach event., (*8)

$handler = 
    function (Event $event) {
        echo 'Hello Rock!'
    };
$instance =  new Foo;
Event::on($instance, 'onAfter', $handler);

Event::off($instance, 'onAfter');

Requirements

  • PHP 5.4+

License

The Rock Events is open-sourced software licensed under the MIT license., (*9)

The Versions

06/11 2015

dev-master

9999999-dev

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

06/11 2015

0.11.0

0.11.0.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

18/10 2015

0.10.6

0.10.6.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

10/07 2015

0.10.5

0.10.5.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

12/06 2015

0.10.4

0.10.4.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

28/05 2015

0.10.3

0.10.3.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

16/03 2015

0.10.2

0.10.2.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

16/02 2015

0.10.0

0.10.0.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe

28/01 2015

0.9.0

0.9.0.0

A simple implementation of Pub/Sub for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

event pubsub publish-subscribe