Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade help from 2x to 3x #1

Open
weierophinney opened this issue Dec 31, 2019 · 0 comments
Open

Upgrade help from 2x to 3x #1

weierophinney opened this issue Dec 31, 2019 · 0 comments

Comments

@weierophinney
Copy link
Member

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]);
        }
    }

Originally posted by @larsroettig at zendframework/zend-eventmanager#75

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

No branches or pull requests

1 participant