Skip to content
Permalink
Browse files

FlushListener

  • Loading branch information
mabar authored and f3l1x committed Nov 18, 2019
1 parent 3c1f6b2 commit b6770da6fe6dd86e1e37ce2e96f058402f227dbd
@@ -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
@@ -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;
@@ -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,
@@ -56,6 +58,9 @@ final class NextrasOrmEventsExtension extends CompilerExtension
'AfterUpdate' => [
'onAfterUpdate' => AfterUpdateListener::class,
],
'Flush' => [
'onFlush' => FlushListener::class,
],
];
/**
@@ -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;
}
@@ -10,7 +10,8 @@ interface LifecycleListener extends
AfterInsertListener,
AfterPersistListener,
AfterRemoveListener,
AfterUpdateListener
AfterUpdateListener,
FlushListener
{
}
@@ -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);

0 comments on commit b6770da

Please sign in to comment.
You can’t perform that action at this time.