PHP Classes

File: tests/event_listeners_tests.php

Recommend this page to a friend!
  Classes of Kiril Savchev   ITE Event Manager   tests/event_listeners_tests.php   Download  
File: tests/event_listeners_tests.php
Role: Example script
Content type: text/plain
Description: Example script
Class: ITE Event Manager
Manage events implementing PSR-14 interface
Author: By
Last change: Format to PSR2
Date: 7 years ago
Size: 1,047 bytes
 

Contents

Class file image Download
<?php

use Ite\EventManager\EventListenerManagerInterface;
use
Ite\EventManager\EventListenerManagerTrait;
use
Ite\EventManager\EventManager;
use
Psr\EventManager\EventInterface;

chdir(realpath(__DIR__ . '/..'));

require_once
'./vendor/autoload.php';

// load psr interfaces if they not exists
// (not part of this package, but included for convenience):
if (!interface_exists('Psr\\EventManager\\EventInterface')) {
    require_once
'./psr/event-manager/EventInterface.php';
}
if (!
interface_exists('Psr\\EventManager\\EventManagerInterface')) {
    require_once
'./psr/event-manager/EventManagerInterface.php';
}

class
EventManagerAwareTests implements EventListenerManagerInterface {

    use
EventListenerManagerTrait;

    protected
$checks = 'asd';

}

$manager = new EventManagerAwareTests();
$manager->setEventManager(new EventManager());

$manager->addEventListener('TestEvent', function (EventInterface $e) {
   
var_dump($e, $this->checks); // wil dump the event object and 'asd'
}, 0, true);

$manager->fire('TestEvent', $manager);