PHP Classes

File: src/Features/Event.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon   src/Features/Event.php   Download  
File: src/Features/Event.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon
Call PHP classes from JavaScript using AJAX
Author: By
Last change:
Date: 4 years ago
Size: 1,492 bytes
 

Contents

Class file image Download
<?php

/**
 * EventListener.php - Trait for event listener and dispatcher.
 *
 * @package jaxon-core
 * @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @copyright 2016 Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
 * @link https://github.com/jaxon-php/jaxon-core
 */

namespace Jaxon\Features;

use
Jaxon\Contracts\Event\Listener as EventListener;

trait
Event
{
   
/**
     * Register an event listener.
     *
     * @return void
     */
   
public function addEventListener(EventListener $xEventListener)
    {
       
jaxon()->di()->getEventDispatcher()->addSubscriber($xEventListener);
    }

   
/**
     * Trigger an event.
     *
     * @param string $sEvent The event name
     *
     * @return void
     */
   
public function triggerEvent($sEvent)
    {
       
jaxon()->di()->getEventDispatcher()->dispatch($sEvent);
    }

   
/**
     * Return an array of events to listen to.
     *
     * This is the default implementation on the EventListener interface.
     *
     * @return array An empty array
     */
   
public function getEvents()
    {
        return [];
    }

   
/**
     * Return an array of events to listen to.
     *
     * This is the implementation of the Lemon\Event\EventSubscriberInterface interface.
     *
     * @return array The event names to listen to
     */
   
public function getSubscribedEvents()
    {
        return
$this->getEvents();
    }
}