@param $type
@param $handler

@return $this
195565
public function register($type, $handler) {
        if ( ! is_array($type)) {
            $type = [$type];
        }

        foreach ($type as $item) {
            $this->addDefinition(
                $this->createDefinition($item, $handler)
            );
        }

        return $this;
    }
798118
public function use_default_handler( HandlerInterface $handler = NULL ) {

		static $done = FALSE;
		if ( $done ) {
			return $this;
		}

		$done = TRUE;

		add_action(
			HandlersRegistry::ACTION_REGISTER,
			function ( HandlersRegistry $registry ) use ( $handler ) {

				$handler = DefaultHandlerFactory::with_default_handler( $handler )
					->create_default_handler();

				$registry->add_handler( $handler, HandlersRegistry::DEFAULT_NAME );
			},
			1
		);

		return $this;
	}
114135
protected <H extends EventHandler> HandlerRegistration addHandler(final H handler, GwtEvent.Type<H> type) {

        return ensureHandlers().addHandlerToSource(type, this, handler);
    }
1020910
public function setType(Type $type = null)
    {
        if ($this->type !== $type) {
            $this->type = $type;
        }

        return $this;
    }
848820
function(type, handler)
	{
		var obj = this.__obj;
		
		if (obj)
		{
			switch (true)
			{
				// TODO Remove the last tiny piece of jQuery support?
				case conbo.$ && obj instanceof conbo.$:
				case window.$ && obj instanceof window.$:
				{
					obj.on(type, handler);
					break;
				}
				
				case obj instanceof conbo.EventDispatcher:
				{
					obj.addEventListener(type, handler);
					break;
				}
				
				default:
				{
					var types = type.split(' ');
					
					types.forEach(function(type)
					{
						obj.addEventListener(type, handler);
					});
				}
			}
		}
		
		return this;
	}
456654
protected function _execute($type, $data)
    {
        if (!isset($this->_handles[$type]))
        {
            $this->_tmp_handles = array();
            $path = \Swoole::$app_path.'/events/'.$type.'.php';
            if (is_file($path))
            {
                $_conf = include $path;
                if ($_conf and isset($_conf['handlers']) and is_array($_conf['handlers']))
                {
                    foreach ($_conf['handlers'] as $h)
                    {
                        if (class_exists($h))
                        {
                            $object = new $h;
                            if ($object instanceof IFace\EventHandler)
                            {
                                $this->_tmp_handles[] = $object;
                                continue;
                            }
                        }
                        trigger_error("invalid event handler[$type|$h]", E_USER_WARNING);
                    }
                }
            }
            $this->_handles[$type] = $this->_tmp_handles;
        }

        foreach($this->_handles[$type] as $handler)
        {
            /**
             * @var  $handler  IFace\EventHandler
             */
            $handler->trigger($type, $data);
        }
        return true;
    }
398102
function( type, handler ) {

      if( handler === void 0 || handler === null )
        throw new Error( 'Missing argument "handler"' )

      if( typeof handler !== 'function' && typeof handler.handleEvent !== 'function' )
        throw new TypeError( 'Handler must be a function.' )

      function wrapper() {
        this.removeListener( type, wrapper )
        typeof handler !== 'function'
          ? handler.handleEvent.apply( handler, arguments )
          : handler.apply( this, arguments )
      }

      this._events[ type ] ?
        this._events[ type ].push( wrapper ) :
        this._events[ type ] = [ wrapper ]

      return this

    }
115618
protected function setHandler(callable $handler): self
    {
        $isValidHandler = $this->checkPublicStaticCallable($handler, [
            'array',
            ContainerInterface::class,
            ServerRequestInterface::class,
        ], ResponseInterface::class);
        if ($isValidHandler === false) {
            // Handler method should have signature
            // `public static methodName(array, ContainerInterface, ServerRequestInterface): ResponseInterface`'
            throw new LogicException($this->getCallableToCacheMessage());
        }

        $this->handler = $handler;

        return $this;
    }
534828
public function handler($handler = null)
    {
        if ($handler !== null) {
            $this->handler = $this->getRealHandler($handler);
        }

        return $this->handler;
    }
953630
public function forType(string $type): HandlerInterface
    {
        $class = $type !== 'object' ? $type : null;

        if ($class === $this->class) {
            return $this;
        }

        $handler = clone $this;
        $handler->class = $class;

        return $handler;
    }
987968
function(type, handler)
	{
		var obj = this.__obj;
		
		if (obj)
		{
			switch (true)
			{
				// TODO Remove the last tiny piece of jQuery support?
				case conbo.$ && obj instanceof conbo.$:
				case window.$ && obj instanceof window.$:
				{
					obj.off(type, handler);
					break;
				}
				
				case obj instanceof conbo.obj:
				{
					obj.removeEventListener(type, handler);
					break;
				}
				
				default:
				{
					var types = type.split(' ');
					
					types.forEach(function(type)
					{
						obj.removeEventListener(type, handler);
					});
				}
			}
		}
		
		return this;
	}
1288557
function(handle, type) {
				this._state.queue.push({
					fn: handle,
					type: type
				});
				if (this._initialised && !this._running && !this._executing)
					this._next();
				return this;
			}
259143
function(type, handler) {
            var handlers = this._handlers[type],
                i,
                len;

            if (handlers instanceof Array) {
                if (!handler) {
                    handlers.length = 0;
                    return;
                }
                for (i = 0, len = handlers.length; i < len; i++) {
                    if (handlers[i] === handler || handlers[i].handler === handler) {
                        handlers.splice(i, 1);
                        break;
                    }
                }
            }
        }
183681
public function forType(string $type): HandlerInterface
    {
        $traversable = null;
        $subtype = null;

        if (strpos($type, '|') !== false && substr($type, -2) === '[]') {
            list($traversable, $type) = explode('|', $type, 2);
            $subtype = substr($type, 0, -2);
        } elseif (substr($type, -2) === '[]') {
            $subtype = substr($type, 0, -2);
        } elseif (is_a($type, Traversable::class, true)) {
            $traversable = $type;
        } elseif ($type !== 'array') {
            throw new LogicException("Unable to use " . get_class($this) . " to cast to $type");
        }

        if ($traversable === $this->traversable && $subtype === $this->subtype) {
            return $this;
        }

        $handler = clone $this;
        $handler->traversable = $traversable;
        $handler->subtype = $subtype;

        return $handler;
    }
697875
public function registerJsonType($name, $handler, $aliases = array())
    {
        $this->typeHandlers[$name] = $handler;
        foreach ($aliases as $alias) {
            $this->typeHandlers[$alias] = $handler;
        }
    }
943719
public function buildQueryType(
        string $type,
        QueryTypeHandlerInterface $handler,
        array $config
    ): QueryTypeInterface {
        $parameterBuilder = $this->parameterBuilderFactory->createParameterBuilder();
        $handler->buildParameters($parameterBuilder);
        $parameterDefinitions = $parameterBuilder->buildParameterDefinitions();

        return QueryType::fromArray(
            [
                'type' => $type,
                'isEnabled' => $config['enabled'],
                'name' => $config['name'] ?? '',
                'handler' => $handler,
                'parameterDefinitions' => $parameterDefinitions,
            ]
        );
    }
441604
public function getController($module, $handler=null, $type='Controller')
	{
	    $module    = isset($module) ? trim($module, '/') : '';
	    $handler   = isset($handler) ? trim($handler, '/') : '';
	    
	    // has module and contain '/': 'demo/demo2'
	    if ($module && strpos($module, '/')) {
	        if ($handler === 'index') {
	            $handler = '';
	        }
	        
            // think about performance, module limit / level.
            $moduleLevel = intval(Config::get('router.module_level')) ? : 1;
            if ($moduleLevel < 0) {
                $moduleLevel = 1;
            } elseif ($moduleLevel > 2) {
                $moduleLevel  = 2;
            }
            
            $parts = explode('/', $module, $moduleLevel + 1);
            
            if (count($parts) <= $moduleLevel) {
                if ($module && $moduleInstance = $this->getModule($module)) {
                    return $moduleInstance->getController(null, $handler, $type);
                }
            }
            
            $mhandler = array_pop($parts);
            $module   = implode('/', $parts);
            
            if ($mhandler === 'index') {
                $mhandler = '';
            }
            $handler = $handler ? $mhandler . '/' . $handler : $mhandler;
            
	        if ($module && $moduleInstance = $this->getModule($module)) {
	            Ioc::logger('router')->debug(sprintf('[find][m][%s]%s:%s', UriHelper::getRelativeUrl(), $module, $handler));
	            return $moduleInstance->getController(null, $handler, $type);
	        } else {
	            return static::getController($module, $handler, $type);
	        }
	    }
	    // has module and not contain '/': 'demo'
	    elseif ($module && $moduleInstance = $this->getModule($module)) {
	        Ioc::logger('router')->debug(sprintf('[find][m][%s]%s:%s', UriHelper::getRelativeUrl(), $module, $handler));
	        
	        return $moduleInstance->getController(null, $handler, $type);
	    }
	    // as controller 'a/b'+'c'
	    else {
            // 如， /a/b 1) 先查找对应控制器 a/b， 2)不存在则查找 a/b/index， 3) 不存在当包含/时则查找 a并把b当作action，不含/时则找 index并把控制器名当作action
            $namespace  = $this->getNamespace();
            $handler = implode('/', [$module, $handler]);
			$handler = trim($handler, '/') ? : 'index'; 
			$className  = Ioc::findClass($handler, $type, $namespace); 
			$action = null; 
			
			Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
			
			if (!$className) {
			    if ($handler == 'index') {
			        return null;
			    }
			    
			    $indexClassName = Ioc::findClass($handler . '/index', $type, $namespace);
			    
			    Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler . '/index'));
			    
			    if ($indexClassName) {
					$handler    = $handler . '/index';
					$className  = $indexClassName;
				} else {
				    if (($pos = strrpos($handler, '/')) !== false) {
				        $action = substr($handler, $pos + 1);
				        $handler = substr($handler, 0, $pos); 
				        $className  = Ioc::findClass($handler, $type, $namespace);
				        
				        Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				        
				        if (!$className) {
				            $handler .= '/index';
				            $className = Ioc::findClass($handler, $type, $namespace);
				            
				            Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				            
				            if (!$className) {
				                return null;
				            }
				        }
				    } else {
				        $action  = $handler;
				        $handler = 'index';
				        $className  = Ioc::findClass($handler, $type, $namespace);
				        
				        Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				        
				        if (!$className) {
				            return null;
				        }
				    }
				}
			}
			
			/** @var $object ControllerInterface */
			$object = new $className($handler);
			
			if (!$object instanceof ControllerInterface) {
			    if (Ioc::app() && Ioc::app()->isCli() && class_exists('\\Wslim\\Console\\Controller')) {
			        $object = new \Wslim\Console\Controller($object);
			    } elseif (Ioc::app() && !Ioc::app()->isCli() && class_exists('\\Wslim\\Web\\Controller')) {
			        $object = new \Wslim\Web\Controller($object);
			    } else {
                    $object = new Controller($object);
			    }
			}
			$object->setModule($this);
			$object->setAction($action);
			
			return $object;
		}
	}