Completed
Push — ezp-30616 ( e3f22a )
by
unknown
17:55
created

BeforePublishVersionEvent::getTranslations()   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 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Event\Content;
10
11
use eZ\Publish\API\Repository\Values\Content\Content;
12
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
13
use eZ\Publish\Core\Event\BeforeEvent;
14
use UnexpectedValueException;
15
16
final class BeforePublishVersionEvent extends BeforeEvent
17
{
18
    /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */
19
    private $versionInfo;
20
21
    /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
22
    private $content;
23
24
    /**
25
     * @var string[]
26
     */
27
    private $translations;
28
29
    public function __construct(VersionInfo $versionInfo, array $translations)
30
    {
31
        $this->versionInfo = $versionInfo;
32
        $this->translations = $translations;
33
    }
34
35
    public function getVersionInfo(): VersionInfo
36
    {
37
        return $this->versionInfo;
38
    }
39
40
    public function getTranslations(): array
41
    {
42
        return $this->translations;
43
    }
44
45
    public function getContent(): Content
46
    {
47
        if (!$this->hasContent()) {
48
            throw new UnexpectedValueException(sprintf('Return value is not set or not a type of %s. Check hasContent() or set it by setContent() before you call getter.', Content::class));
49
        }
50
51
        return $this->content;
52
    }
53
54
    public function setContent(?Content $content): void
55
    {
56
        $this->content = $content;
57
    }
58
59
    public function hasContent(): bool
60
    {
61
        return $this->content instanceof Content;
62
    }
63
}
64