|
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
|
|
|
use Dflydev\DotAccessConfiguration\Configuration as Data; |
|
16
|
|
|
|
|
17
|
|
|
abstract class AbstractSource implements SourceInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Source ID. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $sourceId; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Is raw? |
|
28
|
|
|
* |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $isRaw; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Content. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $content; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Formatted content. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $formattedContent; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Data. |
|
49
|
|
|
* |
|
50
|
|
|
* @var Data |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $data; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Has changed? |
|
56
|
|
|
* |
|
57
|
|
|
* @var bool |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $hasChanged; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Permalink. |
|
63
|
|
|
* |
|
64
|
|
|
* @var Permalink |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $permalink; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* File. |
|
70
|
|
|
* |
|
71
|
|
|
* @var \SplFileInfo |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $file; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Relative pathname. |
|
77
|
|
|
* |
|
78
|
|
|
* @var string |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $relativePathname; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Filename. |
|
84
|
|
|
* |
|
85
|
|
|
* @var string |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $filename; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Use file reference? |
|
91
|
|
|
* |
|
92
|
|
|
* @var bool |
|
93
|
|
|
*/ |
|
94
|
|
|
protected $useFileReference = false; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Can be formatted? |
|
98
|
|
|
* |
|
99
|
|
|
* @var bool |
|
100
|
|
|
*/ |
|
101
|
|
|
protected $canBeFormatted = false; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Is a generator? |
|
105
|
|
|
* |
|
106
|
|
|
* @var bool |
|
107
|
|
|
*/ |
|
108
|
|
|
protected $isGenerator = false; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Is generated? |
|
112
|
|
|
* |
|
113
|
|
|
* @var bool |
|
114
|
|
|
*/ |
|
115
|
|
|
protected $isGenerated = false; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Should be skipped? |
|
119
|
|
|
* |
|
120
|
|
|
* @var bool |
|
121
|
|
|
*/ |
|
122
|
|
|
protected $shouldBeSkipped = false; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Initialize source. |
|
126
|
|
|
* |
|
127
|
|
|
* @param bool $hasChanged Has the Source changed? |
|
128
|
|
|
*/ |
|
129
|
6 |
|
protected function init($hasChanged = null) |
|
130
|
|
|
{ |
|
131
|
6 |
|
if (null !== $hasChanged) { |
|
132
|
|
|
$this->hasChanged = $hasChanged; |
|
133
|
|
|
} |
|
134
|
6 |
|
$this->shouldBeSkipped = false; |
|
135
|
6 |
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* {@inheritdoc} |
|
139
|
|
|
*/ |
|
140
|
3 |
|
public function sourceId() |
|
141
|
|
|
{ |
|
142
|
3 |
|
return $this->sourceId; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* {@inheritdoc} |
|
147
|
|
|
*/ |
|
148
|
|
|
public function isRaw() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->isRaw; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* {@inheritdoc} |
|
155
|
|
|
*/ |
|
156
|
|
|
public function content() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->content; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* {@inheritdoc} |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setContent($content = null) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->content = $content; |
|
167
|
|
|
|
|
168
|
|
|
// If we are setting content, we are going to assume that we should |
|
169
|
|
|
// not be using file references on output. |
|
170
|
|
|
$this->useFileReference = false; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* {@inheritdoc} |
|
175
|
|
|
*/ |
|
176
|
|
|
public function formattedContent() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->formattedContent; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* {@inheritdoc} |
|
183
|
|
|
*/ |
|
184
|
|
|
public function setFormattedContent($formattedContent = null) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->formattedContent = $formattedContent; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* {@inheritdoc} |
|
191
|
|
|
*/ |
|
192
|
8 |
|
public function data() |
|
193
|
|
|
{ |
|
194
|
8 |
|
return $this->data; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* {@inheritdoc} |
|
199
|
|
|
*/ |
|
200
|
|
|
public function hasChanged() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->hasChanged; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* {@inheritdoc} |
|
207
|
|
|
*/ |
|
208
|
|
|
public function setHasChanged() |
|
209
|
|
|
{ |
|
210
|
|
|
$this->hasChanged = true; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* {@inheritdoc} |
|
215
|
|
|
*/ |
|
216
|
|
|
public function setHasNotChanged() |
|
217
|
|
|
{ |
|
218
|
|
|
$this->hasChanged = false; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* {@inheritdoc} |
|
223
|
|
|
*/ |
|
224
|
|
|
public function permalink() |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->permalink; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* {@inheritdoc} |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setPermalink(Permalink $permalink) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->permalink = $permalink; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* {@inheritdoc} |
|
239
|
|
|
*/ |
|
240
|
|
|
public function useFileReference() |
|
241
|
|
|
{ |
|
242
|
|
|
return $this->useFileReference; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* {@inheritdoc} |
|
247
|
|
|
*/ |
|
248
|
4 |
|
public function canBeFormatted() |
|
249
|
|
|
{ |
|
250
|
4 |
|
return $this->canBeFormatted; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* {@inheritdoc} |
|
255
|
|
|
*/ |
|
256
|
|
|
public function isGenerator() |
|
257
|
|
|
{ |
|
258
|
|
|
return $this->isGenerator; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* {@inheritdoc} |
|
263
|
|
|
*/ |
|
264
|
|
|
public function setIsGenerator() |
|
265
|
|
|
{ |
|
266
|
|
|
$this->isGenerator = true; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* {@inheritdoc} |
|
271
|
|
|
*/ |
|
272
|
|
|
public function setIsNotGenerator() |
|
273
|
|
|
{ |
|
274
|
|
|
$this->isGenerator = false; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* {@inheritdoc} |
|
279
|
|
|
*/ |
|
280
|
|
|
public function isGenerated() |
|
281
|
|
|
{ |
|
282
|
|
|
return $this->isGenerated; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* {@inheritdoc} |
|
287
|
|
|
*/ |
|
288
|
|
|
public function setIsGenerated() |
|
289
|
|
|
{ |
|
290
|
|
|
$this->isGenerated = true; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* {@inheritdoc} |
|
295
|
|
|
*/ |
|
296
|
|
|
public function setIsNotGenerated() |
|
297
|
|
|
{ |
|
298
|
|
|
$this->isGenerated = false; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* {@inheritdoc} |
|
303
|
|
|
*/ |
|
304
|
|
|
public function shouldBeSkipped() |
|
305
|
|
|
{ |
|
306
|
|
|
return $this->shouldBeSkipped; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* {@inheritdoc} |
|
311
|
|
|
*/ |
|
312
|
|
|
public function setShouldBeSkipped() |
|
313
|
|
|
{ |
|
314
|
|
|
$this->shouldBeSkipped = true; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* {@inheritdoc} |
|
319
|
|
|
*/ |
|
320
|
|
|
public function setShouldNotBeSkipped() |
|
321
|
|
|
{ |
|
322
|
|
|
$this->shouldBeSkipped = false; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* {@inheritdoc} |
|
327
|
|
|
*/ |
|
328
|
|
|
public function forceReprocess() |
|
329
|
|
|
{ |
|
330
|
|
|
$this->init(true); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* {@inheritdoc} |
|
335
|
|
|
*/ |
|
336
|
7 |
|
public function relativePathname() |
|
337
|
|
|
{ |
|
338
|
7 |
|
return $this->relativePathname; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* {@inheritdoc} |
|
343
|
|
|
*/ |
|
344
|
|
|
public function filename() |
|
345
|
|
|
{ |
|
346
|
|
|
return $this->filename; |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* {@inheritdoc} |
|
351
|
|
|
*/ |
|
352
|
|
|
public function file() |
|
353
|
|
|
{ |
|
354
|
|
|
return $this->file; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* {@inheritdoc} |
|
359
|
|
|
*/ |
|
360
|
|
|
public function url() |
|
361
|
|
|
{ |
|
362
|
|
|
return $this->permalink()->relativeUrlPath(); |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* {@inheritdoc} |
|
367
|
|
|
*/ |
|
368
|
|
|
public function duplicate($newSourceId, array $options = []) |
|
369
|
|
|
{ |
|
370
|
|
|
return new MemorySource( |
|
371
|
|
|
$newSourceId, |
|
372
|
|
|
new Data($this->data->exportRaw()), |
|
373
|
|
|
isset($options['content']) ? $options['content'] : $this->content, |
|
374
|
|
|
isset($options['formattedContent']) ? $options['formattedContent'] : $this->formattedContent, |
|
375
|
|
|
isset($options['relativePathname']) ? $options['relativePathname'] : $this->relativePathname, |
|
376
|
|
|
isset($options['filename']) ? $options['filename'] : $this->filename, |
|
377
|
|
|
isset($options['file']) ? $options['file'] : $this->file, |
|
378
|
|
|
isset($options['isRaw']) ? $options['isRaw'] : $this->isRaw, |
|
379
|
|
|
isset($options['canBeFormatted']) ? $options['canBeFormatted'] : $this->canBeFormatted, |
|
380
|
|
|
isset($options['hasChanged']) ? $options['hasChanged'] : $this->hasChanged |
|
381
|
|
|
); |
|
382
|
|
|
} |
|
383
|
|
|
} |
|
384
|
|
|
|