/** * Initialize this resource * * @return Firal_Event_Dispatcher */ public function init() { $dispatcher = new Firal_Event_Dispatcher(); Firal_Plugin::setDefaultDispatcher($dispatcher); // initialize the plugins $options = $this->getOptions(); // loop through the plugins path, and initialize them $dir = new DirectoryIterator($options['path']); foreach ($dir as $file) { if ($file->isFile() && substr($file->getFilename(), -4, 4) == '.php') { $class = 'Plugin_' . $this->_formatPluginName(substr($file->getFilename(), 0, -4)); include_once $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename(); if (!class_exists($class)) { throw new Firal_Application_Resource_RuntimeException("Plugin file '{$file->getFilename()}' is found, but '{$class}' does not exist."); } // initialize the plugin new $class(); } } return $dispatcher; }
/** * Set the default event dispatcher * * @param Firal_Event_Dispatcher $dispatcher * * @return void */ public static function setDefaultDispatcher(Firal_Event_Dispatcher $dispatcher) { self::$_defaultDispatcher = $dispatcher; }
public function setUp() { $this->_dispatcher = new Firal_Event_Dispatcher(); Firal_Plugin::setDefaultDispatcher($this->_dispatcher); $this->triggered = false; }
/** * Register a user * * @param array $data * * @return bool */ public function register(array $data) { $form = $this->getRegisterForm(); if (!$form->isValid($data)) { return false; } // create a user object $data = $form->getValues(); // check if the user exists if ($this->_mapper->hasUser($data['username'])) { $form->getElement('username')->setErrors(array("User with name '{$form->getValue('username')}' already exists.")); return false; } $user = new Default_Model_User(); $user->setUsername($data['username']); $user->setPassword($data['password']); $user->setEmail($data['email']); $user->setRole('user'); Firal_Plugin::getDefaultDispatcher()->trigger(new Firal_Event($user, 'default.user.register')); // insert the new user $this->_mapper->insert($user); return true; }