Giter Club home page Giter Club logo

codeigniter-symfony-eventdispatcher's Introduction

Symfony EventDispatcher for Codeigniter

Stand-alone library of Symfony EventDispatcher that can be used in any PHP framework or just pure PHP probject.

If you're looking simple one please visit: https://github.com/shinbonlin/PHP-EventDispatcher

What's the different than original?

Nothing is changed except:

  1. Remove namespace and use
  2. Combine mutli files into one file.
  3. ContainerAwareEventDispatcher.php and /DependencyInjection/RegisterListenersPass.php are not included.

Just made it can be easy used in just 10 seconds without installing by Composer.

Symfony EventDispatcher

Original: https://github.com/symfony/EventDispatcher

How to use

Codeigniter

  1. Copy EventDispatcher.php and put it in application/libraries folder.
  2. Create MY_Controller.php in core folder.
  3. Edit MY_Controller.php
class MY_Controller extends CI_Controller
{


    public $event;

	public function __construct() {
        parent::__construct();

		$this->load->library('EventDispatcher');
		$this->event = new EventDispatcher();
    }
}

Register an Event

    $this->event->addListener('event_name', function () {
        echo 'Hello, World!';
    });

Run an Event

    $this->event->dispatch('event_name');

Result

Hello, World!

Pure PHP

Example Code

$event = new EventDispatcher();

$event->addListener('event_name', function () {
    echo 'Hello, World!';
});

$event->dispatch('event_name');

Hope this helps.

codeigniter-symfony-eventdispatcher's People

Contributors

greenjackal avatar

Watchers

 avatar  avatar

Forkers

thavia

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.