Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Upgrade help from 2x to 3x #75

Open
larsroettig opened this issue Jun 21, 2019 · 1 comment
Open

Upgrade help from 2x to 3x #75

larsroettig opened this issue Jun 21, 2019 · 1 comment

Comments

@larsroettig
Copy link

Hi @weierophinney,
I try to update zendframework/zend-eventmanager - ^2.6.3 to ^3.0.0 main Problem in
\Zend\EventManager\SharedEventManager::attach was the return removed. We using this return for caching and detach our events. Is there any migration guide I try to do it by self but I am not sure if this be working as before.

Old:

    /**
     * {@inheritdoc}
     */
 public function attach(EventManagerInterface $events, $priority = 1)
    {
        $sharedEvents = $events->getSharedManager();
        $this->listeners[] = $sharedEvents->attach(
            Application::class,
            MvcEvent::EVENT_BOOTSTRAP,
            [$this, 'onBootstrap'],
            $priority
        );
    }

    /**
     * {@inheritdoc}
     */
    public function detach(EventManagerInterface $events)
    {
        foreach ($this->listeners as $index => $listener) {
            if ($events->detach($listener)) {
                unset($this->listeners[$index]);
            }
        }
    }

New:

 public function attach(EventManagerInterface $events, $priority = 1)
    {
        $sharedEvents = $events->getSharedManager();
        $sharedEvents->attach(
            Application::class,
            MvcEvent::EVENT_BOOTSTRAP,
            [$this, 'onBootstrap'],
            $priority
        );

        $this->listeners = $sharedEvents->getListeners([Application::class],
            MvcEvent::EVENT_BOOTSTRAP);
    }

    /**
     * {@inheritdoc}
     */
    public function detach(EventManagerInterface $events)
    {
        foreach ($this->listeners as $index => $listener) {
                $events->detach($listener);
                unset($this->listeners[$index]);
        }
    }
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-eventmanager; a new issue has been opened at laminas/laminas-eventmanager#1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants