Skip to content

Commit 7033907

Browse files
convert to PHP5
1 parent bbb6ac3 commit 7033907

File tree

3 files changed

+89
-19
lines changed

3 files changed

+89
-19
lines changed

ScriptHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public static function compileCSS(Event $event)
2727

2828
$processor = new Processor($event->getIO());
2929

30-
exec('rm -rf ' . __DIR__ . '/var/*');
31-
3230
foreach ($configs as $config) {
3331
if (!is_array($config)) {
3432
throw new \InvalidArgumentException('The extra.css-compiler should contain only configuration objects.');
@@ -38,7 +36,7 @@ public static function compileCSS(Event $event)
3836
$processor->attachFiles(__DIR__ . "/{$value}", __DIR__ . "/{$config['output']}");
3937
}
4038

41-
$processor->processFiles($config['format'] ?? 'compact');
39+
$processor->processFiles(isset($config['format']) ? $config['format'] : 'compact');
4240
}
4341

4442
$processor->saveOutput();

src/Container/File.php

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,81 +31,131 @@ class File
3131
*/
3232
private $type;
3333

34-
public function __construct(string $sourcePath, string $outputPath)
34+
/**
35+
* @param string $sourcePath
36+
* @param string $outputPath
37+
*/
38+
public function __construct($sourcePath, $outputPath)
3539
{
3640
$this->setSourcePath($sourcePath);
3741
$this->outputPath = $outputPath;
3842
}
3943

40-
public function getSourcePath() : string
44+
public function getSourcePath()
4145
{
4246
return $this->sourcePath;
4347
}
4448

45-
public function setSourcePath(string $path) : self
49+
/**
50+
* @param string $path
51+
*
52+
* @return File
53+
*/
54+
public function setSourcePath($path)
4655
{
4756
$this->sourcePath = $path;
4857
$this->detectSourceTypeFromPath($path);
4958

5059
return $this;
5160
}
5261

53-
public function getOutputPath() : string
62+
/**
63+
* @return string
64+
*/
65+
public function getOutputPath()
5466
{
5567
return $this->outputPath;
5668
}
5769

58-
public function setOutputPath(string $path) : self
70+
/**
71+
* @param string $path
72+
*
73+
* @return File
74+
*/
75+
public function setOutputPath($path)
5976
{
6077
$this->outputPath = $path;
6178

6279
return $this;
6380
}
6481

65-
public function getSourceContent() : string
82+
/**
83+
* @return string
84+
*/
85+
public function getSourceContent()
6686
{
6787
return $this->sourceContent;
6888
}
6989

70-
public function setSourceContent(string $content) : self
90+
/**
91+
* @param string $content
92+
*
93+
* @return File
94+
*/
95+
public function setSourceContent($content)
7196
{
7297
$this->sourceContent = $content;
7398

7499
return $this;
75100
}
76101

77-
public function setSourceContentFromSourcePath() : self
102+
/**
103+
* @return File
104+
* @throws FileException
105+
*/
106+
public function setSourceContentFromSourcePath()
78107
{
79108
$this->sourceContent = $this->readSourceContentByPath();
80109

81110
return $this;
82111
}
83112

84-
public function getParsedContent() : string
113+
/**
114+
* @return string
115+
*/
116+
public function getParsedContent()
85117
{
86118
return $this->parsedContent;
87119
}
88120

89-
public function setParsedContent(string $content) : self
121+
/**
122+
* @param string $content
123+
*
124+
* @return File
125+
*/
126+
public function setParsedContent($content)
90127
{
91128
$this->parsedContent = $content;
92129

93130
return $this;
94131
}
95132

96-
public function getType() : string
133+
/**
134+
* @return string
135+
*/
136+
public function getType()
97137
{
98138
return $this->type;
99139
}
100140

101-
public function setType(string $type) : self
141+
/**
142+
* @param string $type
143+
*
144+
* @return File
145+
*/
146+
public function setType($type)
102147
{
103148
$this->type = $type;
104149

105150
return $this;
106151
}
107152

108-
private function detectSourceTypeFromPath(string $path)
153+
/**
154+
* @param string $path
155+
*
156+
* @return void
157+
*/
158+
private function detectSourceTypeFromPath($path)
109159
{
110160
switch (true) {
111161
case 0 !== preg_match('/^.*\.' . static::TYPE_SCSS . '/', $path):
@@ -125,6 +175,10 @@ private function detectSourceTypeFromPath(string $path)
125175
}
126176
}
127177

178+
/**
179+
* @return string
180+
* @throws FileException
181+
*/
128182
private function readSourceContentByPath()
129183
{
130184
if (!file_exists($this->getSourcePath())) {

src/Processor/Processor.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ protected function initCompilers()
5050
$this->compass = new CompassCompiler($this->sass);
5151
}
5252

53-
public function attachFiles(string $inputPath, string $outputPath)
53+
/**
54+
* @param string $inputPath
55+
* @param string $outputPath
56+
*
57+
* @throws \Exception
58+
*/
59+
public function attachFiles($inputPath, $outputPath)
5460
{
5561
if (is_dir($inputPath)) {
5662
$files = scandir($inputPath);
@@ -71,7 +77,10 @@ public function attachFiles(string $inputPath, string $outputPath)
7177
}
7278
}
7379

74-
public function concatOutput() : array
80+
/**
81+
* @return string[]
82+
*/
83+
public function concatOutput()
7584
{
7685
$outputMap = [];
7786
foreach ($this->files as $file) {
@@ -85,6 +94,9 @@ public function concatOutput() : array
8594
return $outputMap;
8695
}
8796

97+
/**
98+
* save output into file
99+
*/
88100
public function saveOutput()
89101
{
90102
foreach ($this->concatOutput() as $path => $content) {
@@ -100,7 +112,12 @@ public function saveOutput()
100112
}
101113
}
102114

103-
public function processFiles(string $formatter)
115+
/**
116+
* @param string $formatter
117+
*
118+
* @throws CompilerException
119+
*/
120+
public function processFiles($formatter)
104121
{
105122
switch ($formatter) {
106123
case 'compressed':
@@ -135,6 +152,7 @@ public function processFiles(string $formatter)
135152
case static::TYPE_COMPASS:
136153
case static::TYPE_SCSS:
137154
case static::TYPE_SASS:
155+
$this->sass->setFormatter($formatter);
138156
$content = $this->sass->compile($file->getSourceContent());
139157
break;
140158
case static::TYPE_LESS:

0 commit comments

Comments
 (0)