original_string: public function on($name, $fn = null, $priority = 0)
      {
          // ( $names )
          if (is_array($name)) {
              foreach ($name as $item => $fn) {
                  $this->on($item, $fn);
              }
              return $this;
          }
  
          // ( $name, $fn, $priority, $data )
          if (!is_callable($fn)) {
              throw new \InvalidArgumentException(sprintf(
                  'Expected argument of name callable, "%s" given',
                  is_object($fn) ? get_class($fn) : gettype($fn)
              ));
          }
  
          if (!isset($this->handlers[$name])) {
              $this->handlers[$name] = array();
          }
          $this->handlers[$name][$priority][] = $fn;
  
          return $this;
      }
code: public function on($name, $fn = null, $priority = 0)
      {
          // ( $names )
          if (is_array($name)) {
              foreach ($name as $item => $fn) {
                  $this->on($item, $fn);
              }
              return $this;
          }
  
          // ( $name, $fn, $priority, $data )
          if (!is_callable($fn)) {
              throw new \InvalidArgumentException(sprintf(
                  'Expected argument of name callable, "%s" given',
                  is_object($fn) ? get_class($fn) : gettype($fn)
              ));
          }
  
          if (!isset($this->handlers[$name])) {
              $this->handlers[$name] = array();
          }
          $this->handlers[$name][$priority][] = $fn;
  
          return $this;
      }
code_tokens: public function on ( $ name , $ fn = null , $ priority = 0 ) { // ( $names ) if ( is_array ( $ name ) ) { foreach ( $ name as $ item => $ fn ) { $ this -> on ( $ item , $ fn ) ; } return $ this ; } // ( $name, $fn, $priority, $data ) if ( ! is_callable ( $ fn ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected argument of name callable, "%s" given' , is_object ( $ fn ) ? get_class ( $ fn ) : gettype ( $ fn ) ) ) ; } if ( ! isset ( $ this -> handlers [ $ name ] ) ) { $ this -> handlers [ $ name ] = array ( ) ; } $ this -> handlers [ $ name ] [ $ priority ] [ ] = $ fn ; return $ this ; }
docstring: Attach a handler to an event
  
  @param string|array $name The name of event, or an array that the key is event name and the value is event hanlder
  @param callback $fn The event handler
  @param int $priority The event priority
  @throws \InvalidArgumentException when the second argument is not callable
  @return $this
docstring_tokens: Attach a handler to an event