service = $definition['listener']; $this->method = $definition['method']; $this->container = $container; $this->env = $env; } /** * Use the listener as an invokable, allowing direct attachment to an event manager. * * @return callable */ public function __invoke(EventInterface $event) { $listener = $this->fetchListener(); $method = $this->method; return $listener->{$method}($event); } /** * @return callable */ private function fetchListener() { if ($this->listener) { return $this->listener; } // In the future, typehint against Laminas\ServiceManager\ServiceLocatorInterface, // which defines this message starting in v3. if (method_exists($this->container, 'build') && ! empty($this->env)) { $this->listener = $this->container->build($this->service, $this->env); return $this->listener; } $this->listener = $this->container->get($this->service); return $this->listener; } }