|
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\Source; |
|
11
|
|
|
|
|
12
|
|
|
use Nette\Utils\Finder; |
|
13
|
|
|
use SplFileInfo; |
|
14
|
|
|
use Symplify\PHP7_Sculpin\Contract\Source\SourceFileFilter\SourceFileFilterInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class SourceFileStorage |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var SplFileInfo[][] |
|
20
|
|
|
*/ |
|
21
|
|
|
private $sourceFilesByType = []; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var SourceFileFilterInterface[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private $sourceFileFilters = []; |
|
27
|
|
|
|
|
28
|
5 |
|
public function addSourceFileFilter(SourceFileFilterInterface $sourceFileFilter) |
|
29
|
|
|
{ |
|
30
|
5 |
|
$this->sourceFileFilters[$sourceFileFilter->getName()] = $sourceFileFilter; |
|
31
|
5 |
|
$this->sourceFilesByType[$sourceFileFilter->getName()] = []; |
|
32
|
5 |
|
} |
|
33
|
|
|
|
|
34
|
2 |
|
public function loadSourcesFromFinder(Finder $finder) |
|
35
|
|
|
{ |
|
36
|
2 |
|
foreach ($finder as $fileInfo) { |
|
37
|
2 |
|
$this->addSource($fileInfo); |
|
38
|
|
|
} |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
private function addSource(SplFileInfo $fileInfo) |
|
42
|
|
|
{ |
|
43
|
2 |
|
foreach ($this->sourceFileFilters as $sourceFileFilter) { |
|
44
|
2 |
|
if ($sourceFileFilter->matchesFileSource($fileInfo)) { |
|
45
|
2 |
|
$this->sourceFilesByType[$sourceFileFilter->getName()][] = $fileInfo; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return SplFileInfo[] |
|
52
|
|
|
*/ |
|
53
|
2 |
|
public function getStaticFiles() : array |
|
54
|
|
|
{ |
|
55
|
2 |
|
return $this->sourceFilesByType[SourceFileTypes::STATIC]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return SplFileInfo[] |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function getRenderableFiles() : array |
|
62
|
|
|
{ |
|
63
|
2 |
|
return $this->sourceFilesByType[SourceFileTypes::RENDERABLE]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return SplFileInfo[] |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function getConfigurationFiles() : array |
|
70
|
|
|
{ |
|
71
|
2 |
|
return $this->sourceFilesByType[SourceFileTypes::CONFIGURATION]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return SplFileInfo[] |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function getPostFiles() : array |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->sourceFilesByType[SourceFileTypes::POSTS]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return SplFileInfo[] |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function getLayoutFiles() : array |
|
86
|
|
|
{ |
|
87
|
2 |
|
return $this->sourceFilesByType[SourceFileTypes::LAYOUTS]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|