Skip to content

Commit

Permalink
FlushListener
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and f3l1x committed Nov 18, 2019
1 parent 3c1f6b2 commit b6770da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Just add annotation `@<Before/Update>` to your entity or to trait which entity u
* @AfterPersist(App\Model\AfterPersistListener)
* @AfterRemove(App\Model\AfterRemoveListener)
* @AfterUpdate(App\Model\AfterUpdateListener)
* @Flush(App\Model\FlushListener)
*
* @Lifecycle(App\Model\LifecycleListener)
*/
class Foo extends Entity
Expand Down
5 changes: 5 additions & 0 deletions src/DI/NextrasOrmEventsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Contributte\Nextras\Orm\Events\Listeners\BeforePersistListener;
use Contributte\Nextras\Orm\Events\Listeners\BeforeRemoveListener;
use Contributte\Nextras\Orm\Events\Listeners\BeforeUpdateListener;
use Contributte\Nextras\Orm\Events\Listeners\FlushListener;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\ServiceDefinition;
use Nette\DI\ServiceCreationException;
Expand All @@ -31,6 +32,7 @@ final class NextrasOrmEventsExtension extends CompilerExtension
'onAfterPersist' => AfterPersistListener::class,
'onAfterRemove' => AfterRemoveListener::class,
'onAfterUpdate' => AfterUpdateListener::class,
'onFlush' => FlushListener::class,
],
'BeforeInsert' => [
'onBeforeInsert' => BeforeInsertListener::class,
Expand All @@ -56,6 +58,9 @@ final class NextrasOrmEventsExtension extends CompilerExtension
'AfterUpdate' => [
'onAfterUpdate' => AfterUpdateListener::class,
],
'Flush' => [
'onFlush' => FlushListener::class,
],
];

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Listeners/FlushListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace Contributte\Nextras\Orm\Events\Listeners;

use Nextras\Orm\Entity\IEntity;

interface FlushListener
{

/**
* @param IEntity[] $persisted
* @param IEntity[] $removed
*/
public function onFlush(array $persisted, array $removed): void;

}
3 changes: 2 additions & 1 deletion src/Listeners/LifecycleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface LifecycleListener extends
AfterInsertListener,
AfterPersistListener,
AfterRemoveListener,
AfterUpdateListener
AfterUpdateListener,
FlushListener
{

}
9 changes: 9 additions & 0 deletions tests/fixtures/Mocks/Foo/FooLifecycleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public function onBeforeUpdate(IEntity $entity): void
$this->call(__METHOD__, $entity);
}

/**
* @param IEntity[] $persisted
* @param IEntity[] $removed
*/
public function onFlush(array $persisted, array $removed): void
{
// Not implemented
}

public function call(string $method, IEntity $entity): void
{
$method = str_replace(self::class . '::', null, $method);
Expand Down

0 comments on commit b6770da

Please sign in to comment.