Implementing Oxwall OW_EventManager Class

OW_EventManager binds a function to Oxwall event system

Description

The OW_EventManager class provides access to Oxwall event system of framework. Works as simple as it can be – plugins add PHP listeners (callbacks) to manager stack. When an event is triggered the whole stack is called.

An event is triggered using the trigger( OW_Event $event ) method, this returns an object of OW_Event.

Usage

For example purpose, we will create a method that creates user account and send a welcome message with OW_EventManager.

trigger( OW_Event $event )

This method triggers Oxwall event listeners and return an object of OW_Event.

Parameters

  • $event
    OW_Event ( $name, array $params = array(), $dataValue = null )
    • (string|$name) (required)
    • (array|$params ) (required)
    • (mixed|$dataValue)(optional)

Example

 
	
	/**
	* Method to save user
	*/
	public function saveUser( $username, $password, $email, $accountType )
	{
		//Get instance of BOL_UserService
		$userService = BOL_UserService::getInstance();
		
		//Create user account. Returns BOL_User object
		$user = $userService->createUser( $username, $password, $email, $accountType );
		
		//Set new event parameters
		$event = new OW_Event('plugin_key_after_user_register', array(
			'userDto' => $user
		));
		
		//Trigger an event for after registering user
		OW::getEventManager()->trigger($event );
	}

bind( $name, $listener, $priority = null )

Binds listener to event. Callback should be valid PHP callback.

Parameters

  • $name
    • (string|$name)
  • $listener
    • (callback|$listener)
  • $priority
    • (int|$priority)(optional)
    • Default: 1000

Example

You should do this part from your event handler class or from your plugin init.php file.


	/**
	*
	* Bind Event
	*/
	class PLUGINKEY_CLASS_EventHandler
	{
		//Callback for sending welcome message
		public function sendUserWelcome( OW_Event $e )
		{
			//Get event parameters
			$params = $e->getParams();
			
			//BOL_User object
			$user = $params['userDto'];
			
			//Send Welcome letter
			BOL_UserService::getInstance()->sendWellcomeLetter($user);         
		}
		
		public function init()
		{
			//bind sendUserWelcome() method to 'plugin_key_after_user_register' event
			OW::getEventManager()->bind('plugin_key_after_user_register', array($this, 'sendUserWelcome'));
		}
	}

Finally, you can initialize the event handler from your init.php file.

$eventHandler = new PLUGINKEY_CLASS_EventHandler();
$eventHandler->init();

unbind( $name, $listener )

Unbinds listener from event. Callback should be valid PHP callback.

Premium Service

If you seek a custom feature developed for your website or need 24/7 premium support to help you get started with your social network or Skadate dating website, save hours of searching online or wasting money on unnecessary plugins, get in touch with me and let's discuss a suitable plan for your project. Best thing about this service is that you are never placed on hold and get to talk to an expereinced Oxwall/Skadate developer.

Get in Touch

Post Tags:

  • micexmc
  • tighti3l
  • whenc5w
  • yesterdayv2j

One thought on “Implementing Oxwall OW_EventManager Class”

Leave a Reply