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

Leverage generic persistence event classes #2438

Merged
merged 1 commit into from
May 3, 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
9 changes: 3 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Event/LifecycleEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs;

use function assert;

/**
* Lifecycle Events are triggered by the UnitOfWork during lifecycle transitions
* of documents.
*
* @template-extends BaseLifecycleEventArgs<DocumentManager>
Copy link
Member

Choose a reason for hiding this comment

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

I recall we're free to remove assert($dm instanceof DocumentManager); here now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I guessed PHPStan would complain about redundant condition or similar, thanks!

*/
class LifecycleEventArgs extends BaseLifecycleEventArgs
{
Expand All @@ -22,9 +22,6 @@ public function getDocument(): object

public function getDocumentManager(): DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
return $this->getObjectManager();
}
}
10 changes: 4 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Event/LoadClassMetadataEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
namespace Doctrine\ODM\MongoDB\Event;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs;

use function assert;

/**
* Class that holds event arguments for a loadMetadata event.
*
* @template-extends BaseLoadClassMetadataEventArgs<ClassMetadata<object>, DocumentManager>
*/
final class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
{
public function getDocumentManager(): DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
return $this->getObjectManager();
}
}
9 changes: 3 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Event/ManagerEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\Event\ManagerEventArgs as BaseManagerEventArgs;

use function assert;

/**
* Provides event arguments for the flush events.
*
* @template-extends BaseManagerEventArgs<DocumentManager>
*/
class ManagerEventArgs extends BaseManagerEventArgs
{
public function getDocumentManager(): DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
return $this->getObjectManager();
}
}
8 changes: 3 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs;

use function assert;
use function func_num_args;
use function method_exists;
use function trigger_deprecation;

/**
* Provides event arguments for the onClear event.
*
* @template-extends BaseOnClearEventArgs<DocumentManager>
*/
final class OnClearEventArgs extends BaseOnClearEventArgs
{
Expand Down Expand Up @@ -50,10 +51,7 @@ public function __construct($objectManager, $entityClass = null)

public function getDocumentManager(): DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
return $this->getObjectManager();
}

/**
Expand Down