-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Log executed migration (#3)
- Loading branch information
1 parent
4ffdeed
commit 14b9f40
Showing
4 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\EventListener; | ||
|
||
use Doctrine\Common\EventSubscriber; | ||
use Doctrine\Migrations\DependencyFactory; | ||
use Doctrine\Migrations\Event\MigrationsVersionEventArgs; | ||
use Doctrine\Migrations\Events; | ||
use Psr\Log\LoggerInterface; | ||
|
||
final class PrintMigrationVersionListener implements EventSubscriber | ||
{ | ||
private ?LoggerInterface $logger = null; | ||
|
||
public function __construct(private DependencyFactory $dependencyFactory) | ||
{ | ||
} | ||
|
||
public function onMigrationsVersionExecuting(MigrationsVersionEventArgs $args): void | ||
{ | ||
$this->getLogger()->notice(sprintf('Executing %s', $args->getPlan()->getVersion())); | ||
} | ||
|
||
/** | ||
* @return list<Events::*> | ||
*/ | ||
public function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
Events::onMigrationsVersionExecuting, | ||
]; | ||
} | ||
|
||
private function getLogger(): LoggerInterface | ||
{ | ||
if ($this->logger === null) { | ||
$this->logger = $this->dependencyFactory->getLogger(); | ||
} | ||
return $this->logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters