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 exluding |
||
41 | * |
||
42 | * @return array Found files |
||
43 | */ |
||
44 | public static function scan(array $paths, array $extensions, array $excludeFolders = self::EXCLUDING_FOLDERS) |
||
65 | |||
66 | /** |
||
67 | * Build relative path to static resource relatively to web root path. |
||
68 | * |
||
69 | * @param string $relativePath Relative path to static resource |
||
70 | * @param string $parentPath Path to parent entity |
||
71 | * |
||
72 | * @return string Validated relative path to static resource relatively to web root path |
||
73 | * @throws ResourceNotFound |
||
74 | */ |
||
75 | public static function getWebRelativePath($relativePath, $parentPath = '') |
||
79 | |||
80 | /** |
||
81 | * Build correct relative path to static resource using relative path and parent path. |
||
82 | * |
||
83 | * @param string $relativePath Relative path to static resource |
||
84 | * @param string $parentPath Path to parent entity |
||
85 | * @param string $rootPath Root path for relative path building |
||
86 | * |
||
87 | * @return string Validated relative path to static resource |
||
88 | * @throws ResourceNotFound |
||
89 | */ |
||
90 | public static function getRelativePath($relativePath, $parentPath = '', $rootPath = '') |
||
111 | |||
112 | /** |
||
113 | * Build relative path to static resource relatively to project root path. |
||
114 | * |
||
115 | * @param string $relativePath Relative path to static resource |
||
116 | * @param string $parentPath Path to parent entity |
||
117 | * |
||
118 | * @return string Validated relative path to static resource relatively to project root path |
||
119 | * @throws ResourceNotFound |
||
120 | */ |
||
121 | public static function getProjectRelativePath($relativePath, $parentPath = '') |
||
125 | } |
||
126 |