Completed
Push — master ( 65f512...fe0390 )
by Łukasz
26:26
created

ContentContentInfoProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
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
namespace eZ\Publish\Core\Repository\Values\Content;
8
9
use eZ\Publish\API\Repository\Values\Content\ContentInfo as APIContentInfo;
10
use eZ\Publish\Core\Repository\Values\GeneratorProxyTrait;
11
12
/**
13
 * This class represents a (lazy loaded) proxy for a content info value, for use by ContentProxy.
14
 *
15
 * WARNING: Currently only meant for content where we know status, for instance in-direcly usage on search and on
16
 *          locations which currently only support published content. If any of those at some point start to support other
17
 *          statuses this should instead lazy load object in isDraft(), isPublished() and isTrashed() for safety.
18
 *
19
 *
20
 * @internal Meant for internal use by Repository, type hint against API object instead.
21
 */
22
class ContentContentInfoProxy extends APIContentInfo
23
{
24
    use GeneratorProxyTrait;
25
26
    /**
27
     * @var \eZ\Publish\API\Repository\Values\Content\ContentInfo|null
28
     */
29
    protected $object;
30
31
    /**
32
     * @var ContentProxy
33
     */
34
    protected $proxy;
35
36
    public function __construct(ContentProxy $proxy, int $id, $status = APIContentInfo::STATUS_PUBLISHED)
37
    {
38
        $this->proxy = $proxy;
39
        $this->id = $id;
40
41
        // See warning on class doc.
42
        parent::__construct(['status' => $status]);
43
    }
44
45
    /**
46
     * Get the inner content Info value object from ContentProxy.
47
     */
48
    protected function loadObject()
49
    {
50
        $this->object = $this->proxy->getVersionInfo()->getContentInfo();
51
        $this->proxy = null;
52
    }
53
}
54