1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EM\CssCompiler\Container; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @see FileContainerTest |
7
|
|
|
* |
8
|
|
|
* @since 0.1 |
9
|
|
|
*/ |
10
|
|
|
class FileContainer |
11
|
|
|
{ |
12
|
|
|
const TYPE_UNKNOWN = 'unknown'; |
13
|
|
|
const TYPE_SCSS = 'scss'; |
14
|
|
|
const TYPE_LESS = 'less'; |
15
|
|
|
static $supportedTypes = [ |
|
|
|
|
16
|
|
|
self::TYPE_SCSS, |
17
|
|
|
self::TYPE_LESS |
18
|
|
|
]; |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $inputPath; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $outputPath; |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $inputContent; |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $outputContent; |
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $type; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $inputPath |
42
|
|
|
* @param string $outputPath |
43
|
|
|
*/ |
44
|
|
|
public function __construct($inputPath, $outputPath) |
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->setInputPath($inputPath) |
48
|
|
|
->setOutputPath($outputPath); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getOutputPath() |
55
|
|
|
{ |
56
|
|
|
return $this->outputPath; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $path |
61
|
|
|
* |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
public function setOutputPath($path) |
65
|
|
|
{ |
66
|
|
|
$this->outputPath = $path; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getInputContent() |
75
|
|
|
{ |
76
|
|
|
return $this->inputContent; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $content |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
|
|
public function setInputContent($content) |
85
|
|
|
{ |
86
|
|
|
$this->inputContent = $content; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getInputPath() |
92
|
|
|
{ |
93
|
|
|
return $this->inputPath; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $path |
98
|
|
|
* |
99
|
|
|
* @return $this |
100
|
|
|
*/ |
101
|
|
|
public function setInputPath($path) |
102
|
|
|
{ |
103
|
|
|
$this->inputPath = $path; |
104
|
|
|
$this->detectInputTypeByInputPath(); |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getOutputContent() |
113
|
|
|
{ |
114
|
|
|
return $this->outputContent; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $content |
119
|
|
|
* |
120
|
|
|
* @return $this |
121
|
|
|
*/ |
122
|
|
|
public function setOutputContent($content) |
123
|
|
|
{ |
124
|
|
|
$this->outputContent = $content; |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function getType() |
133
|
|
|
{ |
134
|
|
|
return $this->type; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $type |
139
|
|
|
* |
140
|
|
|
* @return $this |
141
|
|
|
*/ |
142
|
|
|
public function setType($type) |
143
|
|
|
{ |
144
|
|
|
$this->type = $type; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
protected function detectInputTypeByInputPath() |
150
|
|
|
{ |
151
|
|
|
$extension = strtolower(pathinfo($this->getInputPath(), PATHINFO_EXTENSION)); |
152
|
|
|
|
153
|
|
|
$type = in_array($extension, static::$supportedTypes) |
|
|
|
|
154
|
|
|
? $extension |
155
|
|
|
: static::TYPE_UNKNOWN; |
156
|
|
|
|
157
|
|
|
$this->setType($type); |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.