public function getMessages($elementName = null)
    {
        if (null === $elementName) {
            $messages = $this->messages;
            foreach ($this->iterator as $name => $element) {
                $messageSet = $element->getMessages();
                if (!is_array($messageSet) &&
                    !$messageSet instanceof Traversable ||
                    empty($messageSet)
                ) {
                    continue;
                }

                $messages[$name] = $messageSet;
            }

            return $messages;
        }

        if (!$this->has($elementName)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid element name "%s" provided to %s',
                $elementName,
                __METHOD__
            ));
        }

        $element = $this->get($elementName);
        return $element->getMessages();
    }