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
|
1 |
|
public function addSourceFileFilter(SourceFileFilterInterface $sourceFileFilter) |
29
|
|
|
{ |
30
|
1 |
|
$this->sourceFileFilters[$sourceFileFilter->getName()] = $sourceFileFilter; |
31
|
1 |
|
$this->sourceFilesByType[$sourceFileFilter->getName()] = []; |
32
|
1 |
|
} |
33
|
|
|
|
34
|
1 |
|
public function loadSourcesFromFinder(Finder $finder) |
35
|
|
|
{ |
36
|
1 |
|
foreach ($finder as $fileInfo) { |
37
|
1 |
|
$this->addSource($fileInfo); |
38
|
|
|
} |
39
|
1 |
|
} |
40
|
|
|
|
41
|
1 |
|
private function addSource(SplFileInfo $fileInfo) |
42
|
|
|
{ |
43
|
1 |
|
foreach ($this->sourceFileFilters as $sourceFileFilter) { |
44
|
1 |
|
if ($sourceFileFilter->matchesFileSource($fileInfo)) { |
45
|
1 |
|
$this->sourceFilesByType[$sourceFileFilter->getName()][] = $fileInfo; |
46
|
|
|
} |
47
|
|
|
} |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return SplFileInfo[] |
52
|
|
|
*/ |
53
|
1 |
|
public function getStaticFiles() : array |
54
|
|
|
{ |
55
|
1 |
|
return $this->sourceFilesByType[SourceFileTypes::STATIC]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return SplFileInfo[] |
60
|
|
|
*/ |
61
|
1 |
|
public function getRenderableFiles() : array |
62
|
|
|
{ |
63
|
1 |
|
return $this->sourceFilesByType[SourceFileTypes::RENDERABLE]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return SplFileInfo[] |
68
|
|
|
*/ |
69
|
1 |
|
public function getConfigurationFiles() : array |
70
|
|
|
{ |
71
|
1 |
|
return $this->sourceFilesByType[SourceFileTypes::CONFIGURATION]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return SplFileInfo[] |
76
|
|
|
*/ |
77
|
1 |
|
public function getPostFiles() : array |
78
|
|
|
{ |
79
|
1 |
|
return $this->sourceFilesByType[SourceFileTypes::POSTS]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return SplFileInfo[] |
84
|
|
|
*/ |
85
|
1 |
|
public function getLayoutFiles() : array |
86
|
|
|
{ |
87
|
1 |
|
return $this->sourceFilesByType[SourceFileTypes::LAYOUTS]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|