|
12 | 12 |
|
13 | 13 | namespace Laravel\Ripple\Built; |
14 | 14 |
|
| 15 | +use FilesystemIterator; |
15 | 16 | use Illuminate\Foundation\Application; |
| 17 | +use Illuminate\Support\Facades\Config; |
| 18 | +use RecursiveDirectoryIterator; |
| 19 | +use RecursiveIteratorIterator; |
16 | 20 | use Ripple\File\File; |
17 | 21 | use Ripple\File\Monitor; |
18 | 22 |
|
19 | | -use function base_path; |
20 | | -use function file_exists; |
| 23 | +use function is_dir; |
| 24 | +use function array_shift; |
| 25 | +use function is_file; |
21 | 26 |
|
22 | 27 | class Factory |
23 | 28 | { |
@@ -98,15 +103,41 @@ public static function defaultServicesToWarm(): array |
98 | 103 | */ |
99 | 104 | public static function createMonitor(): Monitor |
100 | 105 | { |
101 | | - $monitor = File::getInstance()->monitor(); |
102 | | - $monitor->add(base_path('/app')); |
103 | | - $monitor->add(base_path('/bootstrap')); |
104 | | - $monitor->add(base_path('/config')); |
105 | | - $monitor->add(base_path('/routes')); |
106 | | - $monitor->add(base_path('/resources')); |
107 | | - if (file_exists(base_path('/.env'))) { |
108 | | - $monitor->add(base_path('/.env')); |
| 106 | + $monitor = File::getInstance()->monitor(); |
| 107 | + $watchPaths = Config::get('ripple.WATCH_PATHS', []); |
| 108 | + |
| 109 | + $after = []; |
| 110 | + |
| 111 | + foreach ($watchPaths as $path) { |
| 112 | + if (is_file($path)) { |
| 113 | + $monitor->add($path); |
| 114 | + } |
| 115 | + |
| 116 | + if (is_dir($path)) { |
| 117 | + $iterator = new RecursiveIteratorIterator( |
| 118 | + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), |
| 119 | + RecursiveIteratorIterator::SELF_FIRST |
| 120 | + ); |
| 121 | + |
| 122 | + /*** @var \SplFileInfo $file */ |
| 123 | + foreach ($iterator as $file) { |
| 124 | + if ($file->isDir()) { |
| 125 | + $after[] = $file->getPathname(); |
| 126 | + } |
| 127 | + |
| 128 | + if ($file->isFile()) { |
| 129 | + $monitor->add($file->getPathname()); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + $after[] = $path; |
| 134 | + } |
| 135 | + |
| 136 | + while ($path = array_shift($after)) { |
| 137 | + $monitor->add($path); |
| 138 | + } |
109 | 139 | } |
| 140 | + |
110 | 141 | return $monitor; |
111 | 142 | } |
112 | 143 | } |
0 commit comments