public function attachEvents(EventManagerInterface $events, array $eventsSpec = null)
    {
        if (null === $eventsSpec) {
            $eventsSpec = $this->eventsProvider();
        }
		
        foreach ($eventsSpec as $spec) {
            if (!is_array($spec) || 2 > count($spec)) {
                throw new \UnexpectedValueException('Event specification must be an array with at least two entries: event name and method name.');
            }

            $event  = $spec[0];
            $method = $spec[1];
            $priority = isset($spec[2]) ? $spec[2] : 0;

            $this->listeners[] = $events->attach($event, [ $this, $method ], $priority);
        }

        return $this;
    }