|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is a part of Sculpin. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dragonfly Development Inc. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Symplify\PHP7_Sculpin\Source; |
|
13
|
|
|
|
|
14
|
|
|
use Symplify\PHP7_Sculpin\Permalink\Permalink; |
|
15
|
|
|
|
|
16
|
|
|
class ProxySource implements SourceInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var SourceInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $source; |
|
22
|
|
|
|
|
23
|
1 |
|
public function __construct(SourceInterface $source) |
|
24
|
|
|
{ |
|
25
|
1 |
|
$this->source = $source; |
|
26
|
1 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function sourceId() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->source->sourceId(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function isRaw() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->source->isRaw(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function canBeFormatted() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->source->isRaw(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function hasChanged() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->source->hasChanged(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setHasChanged() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->source->setHasChanged(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setHasNotChanged() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->source->setHasNotChanged(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function permalink() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->source->permalink(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setPermalink(Permalink $permalink) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->source->setPermalink($permalink); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function useFileReference() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->source->useFileReference(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritdoc} |
|
102
|
|
|
*/ |
|
103
|
|
|
public function file() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->source->file(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* {@inheritdoc} |
|
110
|
|
|
*/ |
|
111
|
|
|
public function content() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->source->content(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* {@inheritdoc} |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setContent($content = null) |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->source->setContent($content); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* {@inheritdoc} |
|
126
|
|
|
*/ |
|
127
|
|
|
public function formattedContent() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->source->formattedContent(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* {@inheritdoc} |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function setFormattedContent($formattedContent = null) |
|
136
|
|
|
{ |
|
137
|
1 |
|
return $this->source->setFormattedContent($formattedContent); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* {@inheritdoc} |
|
142
|
|
|
*/ |
|
143
|
|
|
public function relativePathname() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->source->relativePathname(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* {@inheritdoc} |
|
150
|
|
|
*/ |
|
151
|
|
|
public function filename() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->source->filename(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* {@inheritdoc} |
|
158
|
|
|
*/ |
|
159
|
|
|
public function data() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->source->data(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* {@inheritdoc} |
|
166
|
|
|
*/ |
|
167
|
|
|
public function isGenerator() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->source->data(); |
|
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* {@inheritdoc} |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setIsGenerator() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->source->setIsGenerator(); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* {@inheritdoc} |
|
182
|
|
|
*/ |
|
183
|
|
|
public function setIsNotGenerator() |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->source->setIsNotGenerator(); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* {@inheritdoc} |
|
190
|
|
|
*/ |
|
191
|
|
|
public function isGenerated() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->source->isGenerated(); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* {@inheritdoc} |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setIsGenerated() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->source->setIsGenerated(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* {@inheritdoc} |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setIsNotGenerated() |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->source->setIsNotGenerated(); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* {@inheritdoc} |
|
214
|
|
|
*/ |
|
215
|
|
|
public function shouldBeSkipped() |
|
216
|
|
|
{ |
|
217
|
|
|
$this->source->shouldBeSkipped(); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* {@inheritdoc} |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setShouldBeSkipped() |
|
224
|
|
|
{ |
|
225
|
|
|
$this->source->setShouldBeSkipped(); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* {@inheritdoc} |
|
230
|
|
|
*/ |
|
231
|
|
|
public function setShouldNotBeSkipped() |
|
232
|
|
|
{ |
|
233
|
|
|
$this->source->setShouldNotBeSkipped(); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* {@inheritdoc} |
|
238
|
|
|
*/ |
|
239
|
|
|
public function forceReprocess() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->source->forceReprocess(); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* {@inheritdoc} |
|
246
|
|
|
*/ |
|
247
|
|
|
public function url() |
|
248
|
|
|
{ |
|
249
|
|
|
return $this->source->url(); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* {@inheritdoc} |
|
254
|
|
|
*/ |
|
255
|
|
|
public function duplicate($newSourceId) |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->source->duplicate($newSourceId); |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.