* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_User' ); /** * Event_Handler_User_StopOnUser * * Stop event processing in case * * @version 1.0.0 * @package WB * @subpackage base */ class WBEvent_Handler_User_StopOnUser extends WBEvent_Handler_User { /** * Handler config * * Parameters: * - user list of groups that must match invert group with "!" prefix * - anonymous what to do for no user: continue (default) or stop * * @var array */ protected $config = array( 'user' => array(), 'anonymous' => 'continue' ); /** * Conditional Stop Event Processing * * Stop processing according to values. By default - if there is no "key", event will be stopped. * If there is a key, it will check event data values against configured values and stop * on match. * * @see isRecoverable() * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { // no user just go on if (empty($this->config['user'])) { return true; } if (!is_array($this->config['user'])) { $this->config['user'] = array($this->config['user']); } // there is no user if (!$this->loadUser($e)) { if ('continue' == $this->config['anonymous']) { $this->debugPrint('Continue beause of anonymous user'); return true; } $this->debugPrint('Stop beause of anonymous user'); return false; } foreach ($this->config['user'] as $user) { $user = trim($user); $xor = false; if ('!' == $user[0]) { $xor = true; $user = substr($user, 1); } $res = ($xor XOR ($this->user->getId() == $user)); if ($res) { if ($xor) { $this->debugPrint('Stop because user is not in not in lise'); } else { $this->debugPrint('Stop because user is in list'); } return false; } } $this->debugPrint('Continue because no stop condition matched'); return true; } }