public function addHandler(array $handler, $key = null)
    {
        if (!isset($handler['type'])) {
            throw new InvalidArgumentException(
                'Handler type is required.'
            );
        }

        if (!is_string($key)) {
            $this->handlers[] = $handler;
        } else {
            $this->handlers[$key] = $handler;
        }

        return $this;
    }