EventPriority::LOWEST){ return false; } $identifier = Utils::getCallableIdentifier($handler); if(isset(static::$handlers[$identifier])){ //Already registered return false; }else{ static::$handlers[$identifier] = $handler; if(!isset(static::$handlerPriority[(int) $priority])){ static::$handlerPriority[(int) $priority] = array(); krsort(static::$handlerPriority); } static::$handlerPriority[(int) $priority][$identifier] = $handler; return true; } } public static function unregister(callable $handler, $priority = EventPriority::NORMAL){ $identifier = Utils::getCallableIdentifier($handler); if(isset(static::$handlers[$identifier])){ if(isset(static::$handlerPriority[(int) $priority][$identifier])){ unset(static::$handlerPriority[(int) $priority][$identifier]); }else{ for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){ unset(static::$handlerPriority[$priority][$identifier]); if(count(static::$handlerPriority[$priority]) === 0){ unset(static::$handlerPriority[$priority]); } } } unset(static::$handlers[$identifier]); return true; }else{ return false; } } protected $eventName = null; private $status = Event::NORMAL; private $prioritySlot; final public function getEventName(){ return $this->eventName !== null ? get_class($this) : $this->eventName; } final public function setPrioritySlot($slot){ $this->prioritySlot = (int) $slot; } final public function getPrioritySlot(){ return (int) $this->prioritySlot; } public function isAllowed(){ return ($this->status & 0x7FFFFFFF) === Event::ALLOW; } public function setAllowed($forceAllow = false){ $this->status = Event::ALLOW | ($forceAllow === true ? Event::FORCE : 0); } public function isCancelled(){ return ($this->status & 0x7FFFFFFF) === Event::DENY; } public function setCancelled($forceCancel = false){ if($this instanceof CancellableEvent){ $this->status = Event::DENY | ($forceCancel === true ? Event::FORCE : 0); } return false; } public function isNormal(){ return $this->status === Event::NORMAL; } public function setNormal(){ $this->status = Event::NORMAL; } public function isForced(){ return ($this->status & Event::FORCE) > 0; } }