Completed
Push — master ( 01e3cc...866d97 )
by
unknown
122:05 queued 96:28
created

BuildSchemaSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
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
        return [
40
            SchemaBuilderEvents::BUILD_SCHEMA => ['onBuildSchema', 200],
41
        ];
42
    }
43
44
    /**
45
     * @param \EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvent $event
46
     */
47
    public function onBuildSchema(SchemaBuilderEvent $event): void
48
    {
49
        $event
50
            ->getSchemaBuilder()
51
            ->importSchemaFromFile($this->schemaFilePath);
52
    }
53
}
54