1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
3
|
|
|
// __________ __ ________ __________ |
4
|
|
|
// \______ \ |__ ______ / _____/ ____ _____ ______\______ \ _______ ___ |
5
|
|
|
// | ___/ | \\____ \/ \ ____/ __ \\__ \\_ __ \ | _// _ \ \/ / |
6
|
|
|
// | | | Y \ |_> > \_\ \ ___/ / __ \| | \/ | ( <_> > < |
7
|
|
|
// |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \ |
8
|
|
|
// \/|__| \/ \/ \/ \/ \/ |
9
|
|
|
// ----------------------------------------------------------------------------- |
10
|
|
|
// Designed and Developed by Brad Jones <brad @="bjc.id.au" /> |
11
|
|
|
// ----------------------------------------------------------------------------- |
12
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
13
|
|
|
|
14
|
|
|
namespace Gears\Asset\Compilers; |
15
|
|
|
|
16
|
|
|
use Gears\Asset\Compilers\Base; |
17
|
|
|
use Symfony\Component\Finder\Finder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Instead of providing individual files, one may provide a path to a folder. |
21
|
|
|
* We will then loop through each file below this folder, concatenating and |
22
|
|
|
* minifying as we go. |
23
|
|
|
* |
24
|
|
|
* > NOTE: This only works for native css and js source files. |
25
|
|
|
* > For example you would not provide a folder to a bunch of less files. |
26
|
|
|
* > You would provide the direct path to a single less file that then imports |
27
|
|
|
* > other less files, just like bootstrap does. |
28
|
|
|
* |
29
|
|
|
* **Order of Concatenation:** Also please pay attention to filenames of your |
30
|
|
|
* files, as this will determine the order they are concatenated together. |
31
|
|
|
*/ |
32
|
|
|
class Folder extends Base |
33
|
|
|
{ |
34
|
|
|
public function compile(): string |
35
|
|
|
{ |
36
|
|
|
$files = new Finder(); |
37
|
|
|
$files->files(); |
38
|
|
|
$files->name('*.'.$this->destination->getExtension()); |
39
|
|
|
$files->in($this->file->getPathname()); |
40
|
|
|
$files->sortByName(); |
41
|
|
|
|
42
|
|
|
foreach ($files as $file) |
43
|
|
|
{ |
44
|
|
|
if ($this->doWeNeedToMinify($file)) |
45
|
|
|
{ |
46
|
|
|
$this->source .= $this->getMinifier($file, $file->getContents())->minify(); |
47
|
|
|
} |
48
|
|
|
else |
49
|
|
|
{ |
50
|
|
|
$this->source .= $file->getContents()."\n\n"; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->source; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|