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

Change parent classes in some events #9876

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ Calling `AbstractQuery::setFetchMode()` with anything else than
`Doctrine\ORM\Mapping::FETCH_LAZY` being used. Relying on that behavior is
deprecated and will result in an exception in 3.0.

## Deprecated `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs`

This method has been deprecated in:

* `Doctrine\ORM\Event\OnClearEventArgs`
* `Doctrine\ORM\Event\OnFlushEventArgs`
* `Doctrine\ORM\Event\PostFlushEventArgs`
* `Doctrine\ORM\Event\PreFlushEventArgs`

It will be removed in 3.0. Use `getObjectManager()` instead.

## Prepare split of output walkers and tree walkers

In 3.0, `SqlWalker` and its child classes won't implement the `TreeWalker`
Expand Down
24 changes: 17 additions & 7 deletions lib/Doctrine/ORM/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs;

/**
* Provides event arguments for the onClear event.
*
* @link www.doctrine-project.org
*
* @extends BaseOnClearEventArgs<EntityManagerInterface>
*/
class OnClearEventArgs extends EventArgs
class OnClearEventArgs extends BaseOnClearEventArgs
{
/** @var EntityManagerInterface */
private $em;

/** @var string|null */
private $entityClass;

Expand All @@ -25,18 +25,28 @@ class OnClearEventArgs extends EventArgs
*/
public function __construct(EntityManagerInterface $em, $entityClass = null)
{
$this->em = $em;
parent::__construct($em);

$this->entityClass = $entityClass;
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}

/**
Expand Down
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/OnFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class OnFlushEventArgs extends EventArgs
class OnFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieve associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PostFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the postFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PostFlushEventArgs extends EventArgs
class PostFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PreFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.com
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PreFlushEventArgs extends EventArgs
class PreFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($file = 'php://output', $context = '')
*/
public function onFlush(OnFlushEventArgs $args)
{
$this->dumpIdentityMap($args->getEntityManager());
$this->dumpIdentityMap($args->getObjectManager());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function onFlush(OnFlushEventArgs $args): void
{
//echo "---preFlush".PHP_EOL;

$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();

foreach ($uow->getScheduledEntityInsertions() as $entity) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testListenerShouldReceiveEntityManagerThroughArgs(): void
{
$this->_em->persist($this->createNewValidUser());
$this->_em->flush();
$receivedEm = $this->listener->receivedArgs->getEntityManager();
$receivedEm = $this->listener->receivedArgs->getObjectManager();
self::assertSame($this->_em, $receivedEm);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OnFlushListener
*/
public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();
$deletions = $uow->getScheduledEntityDeletions();
$updates = $uow->getScheduledEntityUpdates();
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DDC3160OnFlushListener

public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();

foreach ($uow->getScheduledEntityInsertions() as $entity) {
Expand Down