vendor/ibexa/migrations/src/lib/Gateway/MigrationMetadata/BuildSchemaSubscriber.php line 40

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Migration\Gateway\MigrationMetadata;
  8. use Ibexa\Contracts\DoctrineSchema\Event\SchemaBuilderEvent;
  9. use Ibexa\Contracts\DoctrineSchema\SchemaBuilderEvents;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12. * Creates a table for migration metadata during platform install.
  13. *
  14. * @internal
  15. */
  16. final class BuildSchemaSubscriber implements EventSubscriberInterface
  17. {
  18. /** @var \Ibexa\Migration\Gateway\MigrationMetadata\SchemaProvider */
  19. private $schemaProvider;
  20. public function __construct(SchemaProvider $schemaProvider)
  21. {
  22. $this->schemaProvider = $schemaProvider;
  23. }
  24. /**
  25. * @return array<array{string, int}>
  26. */
  27. public static function getSubscribedEvents(): array
  28. {
  29. return [
  30. SchemaBuilderEvents::BUILD_SCHEMA => ['onBuildSchema', 200],
  31. ];
  32. }
  33. public function onBuildSchema(SchemaBuilderEvent $event): void
  34. {
  35. $schema = $event->getSchema();
  36. if ($schema->hasTable($this->schemaProvider->getTableName())) {
  37. return;
  38. }
  39. $this->schemaProvider->buildExpectedTable($schema);
  40. }
  41. }
  42. class_alias(BuildSchemaSubscriber::class, 'Ibexa\Platform\Migration\Gateway\MigrationMetadata\BuildSchemaSubscriber');