1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Symplify |
7
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Symplify\PHP7_Sculpin\Renderable\File; |
11
|
|
|
|
12
|
|
|
use SplFileInfo; |
13
|
|
|
|
14
|
|
|
abstract class AbstractFile |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var SplFileInfo |
18
|
|
|
*/ |
19
|
|
|
protected $fileInfo; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $configuration = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $relativeSource; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $outputPath; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $content; |
40
|
|
|
|
41
|
18 |
|
public function __construct(SplFileInfo $fileInfo, string $relativeSource) |
42
|
|
|
{ |
43
|
18 |
|
$this->relativeSource = $relativeSource; |
44
|
18 |
|
$this->fileInfo = $fileInfo; |
45
|
18 |
|
$this->content = file_get_contents($fileInfo->getRealPath()); |
46
|
18 |
|
} |
47
|
|
|
|
48
|
9 |
|
public function setOutputPath(string $outputPath) |
49
|
|
|
{ |
50
|
9 |
|
$this->outputPath = $outputPath; |
51
|
9 |
|
} |
52
|
|
|
|
53
|
7 |
|
public function getOutputPath() : string |
54
|
|
|
{ |
55
|
7 |
|
return $this->outputPath; |
56
|
|
|
} |
57
|
|
|
|
58
|
8 |
|
public function setRelativeUrl(string $relativeUrl) |
59
|
|
|
{ |
60
|
8 |
|
$this->configuration['relativeUrl'] = $relativeUrl; |
61
|
8 |
|
} |
62
|
|
|
|
63
|
5 |
|
public function getRelativeUrl() : string |
64
|
|
|
{ |
65
|
5 |
|
return $this->configuration['relativeUrl']; |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
public function getRelativeSource() : string |
69
|
|
|
{ |
70
|
1 |
|
return $this->relativeSource; |
71
|
|
|
} |
72
|
|
|
|
73
|
10 |
|
public function getBaseName() : string |
74
|
|
|
{ |
75
|
10 |
|
return $this->fileInfo->getBasename('.' . $this->fileInfo->getExtension()); |
76
|
|
|
} |
77
|
|
|
|
78
|
7 |
|
public function getPrimaryExtension() : string |
79
|
|
|
{ |
80
|
7 |
|
$fileParts = explode('.', $this->fileInfo->getBasename()); |
81
|
7 |
|
if (count($fileParts) > 2) { |
82
|
2 |
|
return $fileParts[count($fileParts) - 2]; |
83
|
|
|
} |
84
|
|
|
|
85
|
6 |
|
return $fileParts[count($fileParts) - 1]; |
86
|
|
|
} |
87
|
|
|
|
88
|
6 |
|
public function getExtension() : string |
89
|
|
|
{ |
90
|
6 |
|
return $this->fileInfo->getExtension(); |
91
|
|
|
} |
92
|
|
|
|
93
|
10 |
|
public function getContent() : string |
94
|
|
|
{ |
95
|
10 |
|
return $this->content; |
96
|
|
|
} |
97
|
|
|
|
98
|
7 |
|
public function changeContent(string $newContent) |
99
|
|
|
{ |
100
|
7 |
|
$this->content = $newContent; |
101
|
7 |
|
} |
102
|
|
|
|
103
|
3 |
|
public function setConfiguration(array $configuration) |
104
|
|
|
{ |
105
|
3 |
|
$this->configuration += $configuration; |
106
|
3 |
|
} |
107
|
|
|
|
108
|
7 |
|
public function getConfiguration() : array |
109
|
|
|
{ |
110
|
7 |
|
return $this->configuration; |
111
|
|
|
} |
112
|
|
|
|
113
|
6 |
|
public function getLayout() : string |
114
|
|
|
{ |
115
|
6 |
|
return $this->configuration['layout'] ?? ''; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|