@@ -11,34 +11,27 @@ class HotCommand extends EventEmitter
11
11
{
12
12
public const EVENT_RELOAD = 'reload ' ;
13
13
14
- public const EVENT_HAS_CHANGED = 'hasChanged ' ;
15
-
16
- protected int $ lastModified ;
17
-
18
14
protected ?HotCache $ cachedScript = null ;
19
15
16
+ protected HotFile $ file ;
17
+
20
18
public function __construct (
21
19
public readonly string $ name ,
22
20
protected readonly RegisteredCommand $ command ,
23
- public readonly string $ file
21
+ public readonly string $ filePath
24
22
) {
25
- $ this ->lastModified = filemtime ( $ file );
23
+ $ this ->file = new HotFile ( $ filePath );
26
24
27
- $ this ->on (self ::EVENT_HAS_CHANGED , static function (self $ command ) {
28
- $ command ->reload ();
25
+ $ this ->file -> on (HotFile ::EVENT_HAS_CHANGED , function () {
26
+ $ this ->reload ();
29
27
});
30
28
}
31
29
32
- public function loadContents (): string
33
- {
34
- return file_get_contents ($ this ->file );
35
- }
36
-
37
30
protected function createCachedScript (): void
38
31
{
39
32
$ className = GeneratorUtils::uuid (8 , range ('a ' , 'z ' ));
40
33
$ temp = BOT_ROOT . '/Core/HMR/ ' . $ className . '.php ' ;
41
- $ contents = preg_replace ('/class\s+([a-zA-Z0-9_]+)/ ' , 'class ' . $ className , $ this ->loadContents ());
34
+ $ contents = preg_replace ('/class\s+([a-zA-Z0-9_]+)/ ' , 'class ' . $ className , $ this ->file -> getContents ());
42
35
$ contents = preg_replace ('/namespace\s+([a-zA-Z0-9_ \\\\]+)/ ' , 'namespace Core \\HMR \\Cached ' , $ contents );
43
36
44
37
$ this ->cachedScript ?->deleteCachedFile();
0 commit comments