public function registerHandler($handler, $type = false)
    {
        if (!is_object($handler)) {
            throw new FilterExecutorException('Handler must be an object.');
        }

        if ($type === false) {
            // Try to guess handler type by class FQN.
            $type = $this->guessHandlerType($handler);

            if ($type === false) {
                throw new FilterExecutorException('Could not guess handler type. Please, provide the type for the handler manually.');
            }
        }

        if (!array_key_exists($type, $this->availableHandlerTypes)) {
            throw new FilterExecutorException(sprintf(
                'Handler type "%s" is not allowed (available handler types: [%s]).',
                $type, implode(', ', array_keys($this->availableHandlerTypes))
            ));
        }

        if (!array_key_exists($type, $this->registeredHandlers)) {
            $this->registeredHandlers[$type] = $handler;
        }

        return $this;
    }