Location: PHPKode > scripts > Event > event/EventWrapper.php
<?php

/**
 * ACE - Advanced Content Environment Framework
 *
 * LICENSE
 *
 * This is a part of ACE - Advanced Content Environment Framework,
 * any usage without permission of the author is prohibited.
 * Licence can be obtained by sending email to hide@address.com
 *
 * @category   ACE
 * @package    ACE
 * @author     Michał Szpakowski
 * @copyright  Copyright (c) 2007 Michał Szpakowski
 * @license    Limited, email hide@address.com
 */

/**
 * @category   ACE
 * @package    Event
 * @copyright  Copyright (c) 2007 Michał Szpakowski
 * @license    Limited, email hide@address.com
 */

class EventWrapper
{
	/**
	 * Name of event. See {@link Event::$__events}, {@link Event::__eventname},
	 * {@link Event::eventExists()}, {@link EventCaller::__eventname},
	 * {@link EventCaller::getName()}
	 *
	 * @var string
	 */
	protected $_eventname;
	
	/**
	 * Event Caller. Instance of EventCaller or one of it's descendants.
	 * {@link EventCaller}
	 *
	 * @var object
	 */
	protected $_caller;
	
	/**
	 * Constructor. See {@link Event::factory()}. The only difference is
	 * that $caller is a string of a class name to create new event caller
	 * inside the EventWrapper class.
	 *
	 * @param string $name
	 * @param int $access
	 * @param string $caller
	 * @param object|string $dataset
	 * @param bool $disposable
	 * @param string $eventinterface
	 */
	public function __construct($name, $access = Event::E_PUBLIC, $caller = null, $dataset = null, $disposable = true, $eventinterface = null)
	{
		if ($caller == null) $this->_caller = new EventCaller();
		elseif (is_string($caller) AND (is_subclass_of($caller,'EventCaller') OR $caller === 'EventCaller')) $this->_caller = new $caller;
		$this->_eventname = Event::factory($name,$access,$this->_caller,$dataset,$disposable,$eventinterface);
	}
	
	/**
	 * Get the name of the called event. See {@link EventWrapper::_eventname}
	 *
	 * @return null|string
	 */
	public function getName()
	{
		return $this->_eventname;
	}
	
	/**
	 * Wrapper for {@link Event::getAccess()}
	 *
	 * @return null|string
	 */
	public function getAccess()
	{
		return Event::getAccess($this->_eventname);
	}
	
	/**
	 * Wrapper for {@link Event::getCallerClass()}
	 *
	 * @return null|string
	 */
	public function getCallerClass()
	{
		return Event::getCallerClass($this->_eventname);
	}
	
	/**
	 * Wrapper for {@link Event::Dataset()}
	 *
	 * @return null|string
	 */
	public function getDataset()
	{
		return Event::getDataset($this->_eventname);
	}
	
	/**
	 * Wrapper for {@link Event::isDisposable()}
	 *
	 * @return bool
	 */
	public function isDisposable()
	{
		return Event::isDisposable($this->_eventname);
	}

	/**
	 * Wrapper for {@link Event::getEventInterface()}
	 *
	 * @return string
	 */
	public function getEventInterface()
	{
		return Event::getEventInterface($this->_eventname);
	}
	
	/**
	 * Wrapper for {@link Event::isListener()}
	 *
	 * @return null|int|bool
	 */
	public function isListener($listener)
	{
		return Event::isListener($this->_eventname,$listener);
	}
	
	/**
	 * Wrapper for {@link Event::addlistener()}
	 *
	 * @return bool|object
	 */
	public function addListener($listener)
	{
		return (Event::addListener($this->_eventname,$listener))?$this:false;
	}
	
	/**
	 * Wrapper for {@link Event::removeListener()}
	 *
	 * @return bool|object
	 */
	public function removeListener($listener)
	{
		return (Event::removeListener($this->_eventname,$listener))?$this:false;
	}

	/**
	 * Wrapper for {@link Event::call()}
	 *
	 * @return bool|object
	 */	
	public function call($dataset = null)
	{
		return (Event::call($this->_eventname,$this->_caller,$dataset))?$this:false;
	}

	/**
	 * Destructor to elegantly destruct Events. {@link Event::callerDestroyed()}
	 * {@link Event::destroyEvent()}
	 * 
	 * @return void
	 */
	public function __destruct()
	{
		if (Event::callerDestroyed($this->_caller,$this->_eventname)) return;
		Event::destroyEvent($this->_eventname,$this->_caller);
	}
}

?>
Return current item: Event