* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * Event_Handler_Stop * * Stop event processing in case * * @version 1.0.0 * @package WB * @subpackage base */ class WBEvent_Handler_Stop extends WBEvent_Handler { /** * Handler config * * Parameters: * - key * - value * - match * * @var array */ protected $config = array( 'key' => '', 'value' => '', 'match' => '' ); /** * 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) { // always stop if (empty($this->config['key'])) { return false; } $key = explode('/', $this->config['key']); $data = $e->get(array_shift($key)); // dig down while (!empty($key)) { // no found if (!is_array($data)) { return true; } $k = array_shift($key); if (!isset($data[$k])) { return true; } $data = $data[$k]; } if (!empty($this->config['match'])) { if (preg_match($this->config['match'], $data)) { return false; } } if (empty($data) && empty($this->config['value'])) { return false; } if ($this->config['value'] == $data) { return false; } return true; } }