예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function getEventManager()
 {
     if (null === $this->event_manager) {
         throw new Exception\NotFoundException(Message::get(Message::MANAGER_NOT_FOUND, get_class()), Message::MANAGER_NOT_FOUND);
     }
     return $this->event_manager;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public static function getEventManagerStatically()
 {
     // manager not found
     $class = get_called_class();
     if (!isset(self::$s_event_manager[$class])) {
         throw new Exception\NotFoundException(Message::get(Message::MANAGER_NOT_FOUND, $class), Message::MANAGER_NOT_FOUND);
     }
     return self::$s_event_manager[$class];
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function setOtherManager($name, Interfaces\EventManagerInterface $manager)
 {
     // you can NOT use composite type as other manager
     if ($manager instanceof Interfaces\EventManagerCompositeInterface) {
         throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_MANAGER, get_class($manager)), Message::INVALID_EVENT_MANAGER);
     }
     $this->manager_pool[$name] = $manager;
     return $this;
 }
예제 #4
0
 /**
  * {@inheritDoc}
  *
  * We are not using complex priority like [ priority, PHP_MAX--]
  */
 public function insert(callable $callable, $priority, $sort = true)
 {
     static $MAX = 9999999;
     if ($priority > 100 || $priority < 0) {
         throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_PRIORITY, $priority), Message::INVALID_EVENT_PRIORITY);
     }
     // key
     $key = $priority * 10000000 + $MAX--;
     $this->queue[$key] = ['data' => $callable, 'priority' => $priority];
     // sort by priority
     if ($sort) {
         $this->sort();
     }
 }
예제 #5
0
 /**
  * Detach callable to event queque
  *
  * @param  string $eventName event name
  * @param  EventListenerInterface|string|null $listener
  *         object/static class name or a callable
  * @param  mixed $callable string | array
  * @return void
  * @throws Exception\InvalidArgumentException
  *         if callable is the wrong format
  * @access protected
  */
 protected function detachIt($eventName, $listener, $callable)
 {
     // queue not found
     if ($eventName != '' && !$this->hasEventQueue($eventName)) {
         return;
     }
     // detach callable directly
     if (is_null($listener)) {
         $xc = [[$callable, 50]];
     } else {
         // get callables from listener object or static listener class
         $xc = $this->makeCallables($listener, $callable, 50);
     }
     if (empty($xc)) {
         throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_CALLABLE, $eventName), Message::INVALID_EVENT_CALLABLE);
     } else {
         if ($eventName != '') {
             $q = $this->getEventQueue($eventName);
             foreach ($xc as $c) {
                 $q->remove($c[0]);
             }
             if ($q->count() === 0) {
                 unset($this->events[$eventName]);
             }
         } else {
             $names = $this->getEventNames();
             foreach ($names as $n) {
                 $q = $this->getEventQueue($n);
                 foreach ($xc as $c) {
                     $q->remove($c[0]);
                 }
                 if ($q->count() === 0) {
                     unset($this->events[$n]);
                 }
             }
         }
     }
 }
예제 #6
0
 /**
  * {@inheritDoc}
  */
 public function setProperty($name, $value)
 {
     if (!is_scalar($name)) {
         throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_PROPERTY, $name), Message::INVALID_EVENT_PROPERTY);
     }
     $this->properties[(string) $name] = $value;
     return $this;
 }
예제 #7
0
 /**
  * Throw BadMethodCallException
  *
  * @param  string $method method name
  * @return void
  * @throws Exception\BadMethodCallException
  * @access protected
  */
 protected function throwsBadMethodCallException($method)
 {
     throw new Exception\BadMethodCallException(Message::get(Message::IMMUTABLE_EVENT_METHOD, $method), Message::IMMUTABLE_EVENT_METHOD);
 }