Completed
Push — qa-cumulative-ezp-31278-31279-... ( cb92e6...b59938 )
by
unknown
21:37
created

ProxyDomainMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
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\Repository\ProxyFactory;
10
11
use eZ\Publish\API\Repository\Repository;
12
use eZ\Publish\API\Repository\Values\Content\Content;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\API\Repository\Values\Content\Language;
15
use eZ\Publish\API\Repository\Values\Content\Location;
16
use eZ\Publish\API\Repository\Values\Content\Section;
17
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
18
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
19
use eZ\Publish\API\Repository\Values\User\User;
20
use ProxyManager\Proxy\LazyLoadingInterface;
21
22
/**
23
 * @internal
24
 */
25
final class ProxyDomainMapper implements ProxyDomainMapperInterface
26
{
27
    /** @var \eZ\Publish\API\Repository\Repository */
28
    private $repository;
29
30
    /** @var \ProxyManager\Factory\LazyLoadingValueHolderFactory */
31
    private $proxyGenerator;
32
33
    public function __construct(Repository $repository, ProxyGeneratorInterface $proxyGenerator)
34
    {
35
        $this->repository = $repository;
36
        $this->proxyGenerator = $proxyGenerator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $proxyGenerator of type object<eZ\Publish\Core\R...roxyGeneratorInterface> is incompatible with the declared type object<ProxyManager\Fact...dingValueHolderFactory> of property $proxyGenerator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
    }
38
39
    public function createContentProxy(
40
        int $contentId,
41
        array $prioritizedLanguages = Language::ALL,
42
        bool $useAlwaysAvailable = true
43
    ): Content {
44
        $initializer = function (
45
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
46
        ) use ($contentId, $prioritizedLanguages, $useAlwaysAvailable): bool {
47
            $initializer = null;
48
            $wrappedObject = $this->repository->getContentService()->loadContent(
49
                $contentId,
50
                $prioritizedLanguages,
51
                null,
52
                $useAlwaysAvailable
53
            );
54
55
            return true;
56
        };
57
58
        return $this->proxyGenerator->createProxy(Content::class, $initializer);
59
    }
60
61
    public function createContentInfoProxy(int $contentId): ContentInfo
62
    {
63
        $initializer = function (
64
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
65
        ) use ($contentId): bool {
66
            $initializer = null;
67
            $wrappedObject = $this->repository->getContentService()->loadContentInfo(
68
                $contentId
69
            );
70
71
            return true;
72
        };
73
74
        return $this->proxyGenerator->createProxy(ContentInfo::class, $initializer);
75
    }
76
77 View Code Duplication
    public function createContentTypeProxy(
78
        int $contentTypeId,
79
        array $prioritizedLanguages = Language::ALL
80
    ): ContentType {
81
        $initializer = function (
82
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
83
        ) use ($contentTypeId, $prioritizedLanguages): bool {
84
            $initializer = null;
85
            $wrappedObject = $this->repository->getContentTypeService()->loadContentType(
86
                $contentTypeId,
87
                $prioritizedLanguages
88
            );
89
90
            return true;
91
        };
92
93
        return $this->proxyGenerator->createProxy(ContentType::class, $initializer);
94
    }
95
96 View Code Duplication
    public function createContentTypeGroupProxy(
97
        int $contentTypeGroupId,
98
        array $prioritizedLanguages = Language::ALL
99
    ): ContentTypeGroup {
100
        $initializer = function (
101
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
102
        ) use ($contentTypeGroupId, $prioritizedLanguages): bool {
103
            $initializer = null;
104
            $wrappedObject = $this->repository->getContentTypeService()->loadContentTypeGroup(
105
                $contentTypeGroupId,
106
                $prioritizedLanguages
107
            );
108
109
            return true;
110
        };
111
112
        return $this->proxyGenerator->createProxy(ContentTypeGroup::class, $initializer);
113
    }
114
115
    public function createContentTypeGroupProxyList(
116
        array $contentTypeGroupIds,
117
        array $prioritizedLanguages = Language::ALL
118
    ): array {
119
        $groups = [];
120
        foreach ($contentTypeGroupIds as $contentTypeGroupId) {
121
            $groups[] = $this->createContentTypeGroupProxy($contentTypeGroupId, $prioritizedLanguages);
122
        }
123
124
        return $groups;
125
    }
126
127
    public function createLanguageProxy(string $languageCode): Language
128
    {
129
        $initializer = function (
130
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
131
        ) use ($languageCode): bool {
132
            $initializer = null;
133
            $wrappedObject = $this->repository->getContentLanguageService()->loadLanguage($languageCode);
134
135
            return true;
136
        };
137
138
        return $this->proxyGenerator->createProxy(Language::class, $initializer);
139
    }
140
141
    public function createLanguageProxyList(array $languageCodes): array
142
    {
143
        $languages = [];
144
        foreach ($languageCodes as $languageCode) {
145
            $languages[] = $this->createLanguageProxy($languageCode);
146
        }
147
148
        return $languages;
149
    }
150
151 View Code Duplication
    public function createLocationProxy(
152
        int $locationId,
153
        array $prioritizedLanguages = Language::ALL
154
    ): Location {
155
        $initializer = function (
156
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
157
        ) use ($locationId, $prioritizedLanguages): bool {
158
            $initializer = null;
159
            $wrappedObject = $this->repository->getLocationService()->loadLocation(
160
                $locationId,
161
                $prioritizedLanguages
162
            );
163
164
            return true;
165
        };
166
167
        return $this->proxyGenerator->createProxy(Location::class, $initializer);
168
    }
169
170
    public function createSectionProxy(int $sectionId): Section
171
    {
172
        $initializer = function (
173
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
174
        ) use ($sectionId): bool {
175
            $initializer = null;
176
            $wrappedObject = $this->repository->getSectionService()->loadSection($sectionId);
177
178
            return true;
179
        };
180
181
        return $this->proxyGenerator->createProxy(Section::class, $initializer);
182
    }
183
184 View Code Duplication
    public function createUserProxy(int $userId, array $prioritizedLanguages = Language::ALL): User
185
    {
186
        $initializer = function (
187
            &$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer
188
        ) use ($userId, $prioritizedLanguages): bool {
189
            $initializer = null;
190
            $wrappedObject = $this->repository->getUserService()->loadUser($userId, $prioritizedLanguages);
191
192
            return true;
193
        };
194
195
        return $this->proxyGenerator->createProxy(User::class, $initializer);
196
    }
197
}
198