@@ -31,12 +31,12 @@ public function __construct(private array $watchFor, array $excludes, callable $
3131 }
3232
3333
34- public function addChange (string $ filename , ChangeType $ type ): void
34+ protected function addChange (string $ filename , ChangeType $ type ): void
3535 {
3636 $ this ->changes [] = ['name ' => $ filename , 'type ' => $ type , 'data ' => filemtime ($ filename )];
3737 }
3838
39- public function checkFile (string $ file ): void
39+ protected function checkFile (string $ file ): void
4040 {
4141 if (!array_key_exists ($ file , $ this ->files ) && file_exists ($ file )) {
4242 $ this ->addChange ($ file , ChangeType::NEW );
@@ -60,12 +60,12 @@ public function checkFile(string $file): void
6060 }
6161 }
6262
63- public function clearChanges (): void
63+ protected function clearChanges (): void
6464 {
6565 $ this ->changes = [];
6666 }
6767
68- public function commit (): void
68+ protected function commit (): void
6969 {
7070 $ totalChanges = count ($ this ->changes );
7171 foreach ($ this ->changes as $ change ) {
@@ -94,7 +94,7 @@ public function checkChanges(): void
9494
9595 foreach ($ this ->watchFor as $ watchFor ) {
9696 if (is_dir ($ watchFor )) {
97- $ allFiles = new RecursiveTreeIterator (new RecursiveDirectoryIterator (__DIR__ , RecursiveDirectoryIterator::SKIP_DOTS ));
97+ $ allFiles = new RecursiveTreeIterator (new RecursiveDirectoryIterator ($ watchFor , RecursiveDirectoryIterator::SKIP_DOTS ));
9898 foreach ($ allFiles as $ file ) {
9999 $ filename = trim (str_replace (['| ' , ' ' , '~ ' , '\\' ], '' , $ file ), '- ' );
100100 $ filename = is_dir ($ filename ) ? $ filename . '/ ' : $ filename ;
@@ -117,8 +117,11 @@ public function checkChanges(): void
117117
118118 $ this ->commit ();
119119
120+ if (!$ this ->initialized ) {
121+ $ this ->initialized = true ;
122+ }
123+
120124 $ this ->checking = false ;
121- $ this ->initialized = true ;
122125 }
123126
124127 public function tick (?callable $ handler = null ): void
@@ -136,7 +139,7 @@ public function tick(?callable $handler = null): void
136139 $ this ->tick (function ($ checkChanges , $ interval ) {
137140 do {
138141 call_user_func ($ checkChanges );
139- sleep ($ interval );
142+ sleep ($ interval / 1000 );
140143 } while (true );
141144 });
142145 }
0 commit comments