Completed
Push — master ( 81acf3...241a18 )
by
unknown
60:32 queued 45:22
created

ContentProxy::getThumbnail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 2
dl 0
loc 8
c 0
b 0
f 0
cc 2
nop 0
rs 10
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\Content as APIContent;
10
use eZ\Publish\API\Repository\Values\Content\Thumbnail;
11
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
12
use eZ\Publish\Core\Repository\Values\GeneratorProxyTrait;
13
14
/**
15
 * This class represents a (lazy loaded) proxy for a content value.
16
 *
17
 * @internal Meant for internal use by Repository, type hint against API object instead.
18
 */
19
class ContentProxy extends APIContent
20
{
21
    use GeneratorProxyTrait;
22
23
    /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
24
    protected $object;
25
26
    /** @var ContentContentInfoProxy|null */
27
    protected $contentInfoProxy;
28
29
    public function __get($name)
30
    {
31
        if ($name === 'id') {
32
            return $this->id;
33
        }
34
35
        if ($name === 'contentInfo') {
36
            return $this->getContentInfo();
37
        }
38
39
        if ($name === 'thumbnail') {
40
            return $this->getThumbnail();
41
        }
42
43
        if ($this->object === null) {
44
            $this->loadObject();
45
        }
46
47
        return $this->object->$name;
48
    }
49
50
    public function __isset($name)
51
    {
52
        if ($name === 'id' || $name === 'contentInfo' || $name === 'thumbnail') {
53
            return true;
54
        }
55
56
        if ($this->object === null) {
57
            $this->loadObject();
58
        }
59
60
        return isset($this->object->$name);
61
    }
62
63
    /**
64
     * Return content info, in proxy form if we have not loaded object yet.
65
     *
66
     * For usage in among others DomainMapper->buildLocation() to make sure we can lazy load content info retrieval.
67
     *
68
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
69
     */
70
    protected function getContentInfo()
71
    {
72
        if ($this->object === null) {
73
            if ($this->contentInfoProxy === null) {
74
                $this->contentInfoProxy = new ContentContentInfoProxy($this, $this->id);
75
            }
76
77
            return $this->contentInfoProxy;
78
        } elseif ($this->contentInfoProxy !== null) {
79
            // Remove ref when we no longer need the proxy
80
            $this->contentInfoProxy = null;
81
        }
82
83
        return $this->object->getVersionInfo()->getContentInfo();
84
    }
85
86
    public function getVersionInfo()
87
    {
88
        if ($this->object === null) {
89
            $this->loadObject();
90
        }
91
92
        return $this->object->getVersionInfo();
93
    }
94
95
    public function getContentType(): ContentType
96
    {
97
        if ($this->object === null) {
98
            $this->loadObject();
99
        }
100
101
        return $this->object->getContentType();
102
    }
103
104
    public function getFieldValue($fieldDefIdentifier, $languageCode = null)
105
    {
106
        if ($this->object === null) {
107
            $this->loadObject();
108
        }
109
110
        return $this->object->getFieldValue($fieldDefIdentifier, $languageCode);
111
    }
112
113
    public function getFields()
114
    {
115
        if ($this->object === null) {
116
            $this->loadObject();
117
        }
118
119
        return $this->object->getFields();
120
    }
121
122
    public function getFieldsByLanguage($languageCode = null)
123
    {
124
        if ($this->object === null) {
125
            $this->loadObject();
126
        }
127
128
        return $this->object->getFieldsByLanguage($languageCode);
129
    }
130
131
    public function getField($fieldDefIdentifier, $languageCode = null)
132
    {
133
        if ($this->object === null) {
134
            $this->loadObject();
135
        }
136
137
        return $this->object->getField($fieldDefIdentifier, $languageCode);
138
    }
139
140
    public function getThumbnail(): ?Thumbnail
141
    {
142
        if ($this->object === null) {
143
            $this->loadObject();
144
        }
145
146
        return $this->object->getThumbnail();
147
    }
148
}
149