1 | <?php |
||
15 | class Resource |
||
16 | { |
||
17 | /** Collection of excluding scanning folder patterns */ |
||
18 | const EXCLUDING_FOLDERS = [ |
||
19 | '*/cache/*', |
||
20 | '*/tests/*', |
||
21 | '*/vendor/*/vendor/*' |
||
22 | ]; |
||
23 | |||
24 | /** @var string Full path to project web root directory */ |
||
25 | public static $webRoot; |
||
26 | |||
27 | /** @var string Full path to project root directory */ |
||
28 | public static $projectRoot; |
||
29 | |||
30 | /** |
||
31 | * Recursively scan collection of paths to find assets with passed |
||
32 | * extensions. Method is based on linux find command so this method |
||
33 | * can face difficulties on other OS. |
||
34 | * |
||
35 | * TODO: Add windows support |
||
36 | * TODO: Check if CMD commands can be executed |
||
37 | * |
||
38 | * @param array $paths Paths for files scanning |
||
39 | * @param array $extensions File extension filter |
||
40 | * @param array $excludeFolders Path patterns for excluding |
||
41 | * |
||
42 | * @return array Found files |
||
43 | */ |
||
44 | 1 | public static function scan(array $paths, array $extensions, array $excludeFolders = self::EXCLUDING_FOLDERS) |
|
78 | |||
79 | /** |
||
80 | * Build relative path to static resource relatively to web root path. |
||
81 | * |
||
82 | * @param string $relativePath Relative path to static resource |
||
83 | * @param string $parentPath Path to parent entity |
||
84 | * |
||
85 | * @return string Validated relative path to static resource relatively to web root path |
||
86 | * @throws ResourceNotFound |
||
87 | */ |
||
88 | public static function getWebRelativePath($relativePath, $parentPath = '') |
||
92 | |||
93 | /** |
||
94 | * Build correct relative path to static resource using relative path and parent path. |
||
95 | * |
||
96 | * @param string $relativePath Relative path to static resource |
||
97 | * @param string $parentPath Path to parent entity |
||
98 | * @param string $rootPath Root path for relative path building |
||
99 | * |
||
100 | * @return string Validated relative path to static resource |
||
101 | * @throws ResourceNotFound |
||
102 | */ |
||
103 | 1 | public static function getRelativePath($relativePath, $parentPath = '', $rootPath = '') |
|
124 | |||
125 | /** |
||
126 | * Build relative path to static resource relatively to project root path. |
||
127 | * |
||
128 | * @param string $relativePath Relative path to static resource |
||
129 | * @param string $parentPath Path to parent entity |
||
130 | * |
||
131 | * @return string Validated relative path to static resource relatively to project root path |
||
132 | * @throws ResourceNotFound |
||
133 | */ |
||
134 | 1 | public static function getProjectRelativePath($relativePath, $parentPath = '') |
|
138 | } |
||
139 |