<?php

namespace Engine\Plugins;

/**
 * The class is used for registering a new plugin. It is extended in a class which is automatically
 * executed.
 * @author Gabriel
 */
abstract class RegisterAbstract
{

	/**
	 * The list of observers for a registered plugin.
	 * @var array - associative array of [triggerName][index][\Engine\Plugins\Observer object]
	 */
	protected $observers=[];


	/**
	 * The constructor will register the current plugin.
	 */
	public function __construct()
	{
		$this->register();
	}


	/**
	 * Stores a new observer for this plugin (the method is called from the defined method register()
	 * in the concrete classes.
	 * @param String $triggerName - the trigger name
	 * @param \Engine\Plugins\Observer $obs - the observer object
	 * @throws \Exception - if the triger name is not correct
	 */
	protected function addObserver($triggerName, \Engine\Plugins\Observer $obs)
	{
		// check trigger name
		if (!$triggerName) {
			throw new \Exception('The trigger name was not set in '.get_called_class().'::'.__FUNCTION__.".");
		}
		$this->observers[$triggerName][] = $obs;
	}


	/**
	 * The method will add new observers to the current plugin (using the addObserver() method.
	 */
	abstract protected function register();


	/**
	 * Returns the list of observers for the current
	 * @return multitype:
	 */
	public function getObservers()
	{
		return $this->observers;
	}


}