Completed
Push — ezp-29938-install-schema-using... ( 1a7e83 )
by
unknown
95:17 queued 56:12
created

BuildSchemaSubscriber::getSubscribedEvents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace EzSystems\PlatformInstallerBundle\Event\Subscriber;
12
13
use EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvent;
14
use EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvents;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
17
class BuildSchemaSubscriber implements EventSubscriberInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $schemaFilePath;
23
24
    /**
25
     * @param string $schemaFilePath Path to Yaml schema definition supported by SchemaBuilder
26
     */
27
    public function __construct(string $schemaFilePath)
28
    {
29
        $this->schemaFilePath = $schemaFilePath;
30
    }
31
32
    /**
33
     * Returns an array of events this subscriber wants to listen to.
34
     *
35
     * @return array
36
     */
37
    public static function getSubscribedEvents(): array
38
    {
39
        // BC layer
40
        if (!class_exists(SchemaBuilderEvents::class)) {
41
            return [];
42
        }
43
44
        return [
45
            SchemaBuilderEvents::BUILD_SCHEMA => ['onBuildSchema', 200],
46
        ];
47
    }
48
49
    /**
50
     * @param \EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvent $event
51
     */
52
    public function onBuildSchema(SchemaBuilderEvent $event): void
53
    {
54
        $event
55
            ->getSchemaBuilder()
56
            ->importSchemaFromFile($this->schemaFilePath);
57
    }
58
}
59