Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

VersionBuilder.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\SPI\Limitation\Target\Builder;
10
11 use eZ\Publish\API\Repository\Values\Content\Field;
12 use eZ\Publish\API\Repository\Values\Content\VersionInfo;
13 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
14 use eZ\Publish\SPI\Limitation\Target;
15
21 final class VersionBuilder
22 {
24 private $targetVersionProperties = [];
25
26 public function build(): Target\Version
27 {
28 return new Target\Version($this->targetVersionProperties);
29 }
30
40 public function translateToAnyLanguageOf(array $languageCodes): self
41 {
42 foreach ($languageCodes as $languageCode) {
43 if (!is_string($languageCode) || empty($languageCode)) {
44 throw new InvalidArgumentException('$languageCodes', 'All language codes should be non-empty strings');
45 }
46 }
47
48 $this->targetVersionProperties['allLanguageCodesList'] = $languageCodes;
49
50 return $this;
51 }
52
62 public function createFromAnyContentTypeOf(array $contentTypeIds): self
63 {
64 foreach ($contentTypeIds as $contentTypeId) {
65 if (!\is_int($contentTypeId)) {
66 throw new InvalidArgumentException('$contentTypeIds', 'All contentType ids should be integers');
67 }
68 }
69
70 $this->targetVersionProperties['allContentTypeIdsList'] = $contentTypeIds;
71
72 return $this;
73 }
74
88 public function changeStatusTo(int $status): self
89 {
90 if (!in_array(
91 $status,
92 [VersionInfo::STATUS_DRAFT, VersionInfo::STATUS_PUBLISHED, VersionInfo::STATUS_ARCHIVED]
93 )) {
94 throw new InvalidArgumentException(
95 '$status',
96 'Status should be one of the following: STATUS_DRAFT, STATUS_PUBLISHED, STATUS_ARCHIVED'
97 );
98 }
99
100 $this->targetVersionProperties['newStatus'] = $status;
101
102 return $this;
103 }
104
113 public function updateFieldsTo(?string $initialLanguageCode, array $fields): self
114 {
115 $languageCodes = array_map(
116 function (Field $field) {
117 return $field->languageCode;
118 },
119 $fields
120 );
121
122 $this->targetVersionProperties['forUpdateInitialLanguageCode'] = $initialLanguageCode;
123 $this->targetVersionProperties['forUpdateLanguageCodesList'] = array_values(
124 array_unique($languageCodes)
125 );
126
127 return $this;
128 }
129
139 public function publishTranslations(array $languageCodes): self
140 {
141 foreach ($languageCodes as $languageCode) {
142 if (!is_string($languageCode) || empty($languageCode)) {
143 throw new InvalidArgumentException('$languageCodes', 'All language codes should be non-empty strings');
144 }
145 }
146
147 $this->targetVersionProperties['forPublishLanguageCodesList'] = $languageCodes;
148
149 return $this;
150 }
151 }
eZ\Publish\API\Repository\Values\Content\Field
Definition: API/Repository/Values/Content/Field.php:21
eZ\Publish\API\Repository\Values\Content\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder
Builder of \eZ\Publish\SPI\Limitation\Target\Version instance.
Definition: VersionBuilder.php:22
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\$targetVersionProperties
$targetVersionProperties
Definition: VersionBuilder.php:24
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\build
build()
Definition: VersionBuilder.php:26
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\translateToAnyLanguageOf
translateToAnyLanguageOf(array $languageCodes)
Set intent to translate, to an unspecified (yet) language, any from the given list.
Definition: VersionBuilder.php:40
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\createFromAnyContentTypeOf
createFromAnyContentTypeOf(array $contentTypeIds)
Set intent to create Content from unspecified (yet) content type, any from the given list.
Definition: VersionBuilder.php:62
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\publishTranslations
publishTranslations(array $languageCodes)
Set intent to publish, to specified translations, all from the given list.
Definition: VersionBuilder.php:139
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\changeStatusTo
changeStatusTo(int $status)
Set intent to change Version status.
Definition: VersionBuilder.php:88
eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder\updateFieldsTo
updateFieldsTo(?string $initialLanguageCode, array $fields)
Set intent to update Content Version Fields.
Definition: VersionBuilder.php:113
eZ\Publish\SPI\Limitation\Target\Version
Definition: SPI/Limitation/Target/Version.php:25
eZ\Publish\SPI\Limitation\Target
Marker interface for PermissionResolver::canUser $targets objects.
Definition: SPI/Limitation/Target.php:19
eZ\Publish\SPI\Limitation\Target\Builder
Definition: VersionBuilder.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.