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

Deprecate extension via Doctrine Event Manager #5786

Merged
merged 2 commits into from
Oct 22, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented Oct 22, 2022

Q A
Type deprecation

Closes #5784.

@morozov morozov added this to the 3.5.0 milestone Oct 22, 2022
@morozov morozov linked an issue Oct 22, 2022 that may be closed by this pull request
UPGRADE.md Outdated
Comment on lines 16 to 18
- `AbsractPlatform::$_eventManager`,
- `AbsractPlatform::getEventManager()`,
- `AbsractPlatform::setEventManager()`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `AbsractPlatform::$_eventManager`,
- `AbsractPlatform::getEventManager()`,
- `AbsractPlatform::setEventManager()`,
- `AbstractPlatform::$_eventManager`,
- `AbstractPlatform::getEventManager()`,
- `AbstractPlatform::setEventManager()`,

@morozov morozov merged commit b66f55c into doctrine:3.5.x Oct 22, 2022
@morozov morozov deleted the deprecate-event-manager branch October 22, 2022 14:33
@VincentLanglet
Copy link
Contributor

Hi,

I use in my test the following code

$this->entityManager = EntityManager::create($connection, $config);

        $this->entityManager
            ->getConnection()
            ->getEventManager()
            ->addEventSubscriber(new TimestampableListener());

When i'm creating a custom entityManager, because I use doctrine-extensions:
https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/src/Timestampable/TimestampableListener.php

Does this deprecation means that all the listener from doctrine-extensions will be rewritten ? Or is there another way to set them manually ?

@derrabus
Copy link
Member

That listener does not listen on any DBAL events, so you won't have a problem.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Oct 28, 2022

That listener does not listen on any DBAL events, so you won't have a problem.

My test are failing if I remove

$this->entityManager
            ->getConnection()
            ->getEventManager()
            ->addEventSubscriber(new TimestampableListener());

thought.

And since the latest version, I get a phpstan error since getEventManager is deprecated, which was the issue I wanted to solve.

it turns out that

$eventManager = new EventManager();
$eventManager->addEventSubscriber(new TimestampableListener());

$this->entityManager = EntityManager::create($connection, $config, $eventManager);

is working, without any deprecation. So I'll do this way, but I dunno why the difference and why one way was deprecated.

@derrabus
Copy link
Member

You retrieved the event manager from the database connection to register event listeners for the entity manager. That does not sound like a good idea, does it.

@derrabus
Copy link
Member

$this->entityManager->getConnection()->getEventManager()

vs.

$this->entityManager->getEventManager()

@VincentLanglet
Copy link
Contributor

Oh I see. Thanks

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate extension via Doctrine Event Manager
4 participants