11#!/usr/bin/env php
22<?php
33
4- use Amp \Delayed ;
5- use Amp \Loop ;
6- use Phpactor \AmpFsWatch \ModifiedFile ;
74use Phpactor \AmpFsWatch \WatcherConfig ;
85use Phpactor \AmpFsWatch \Watcher \Fallback \FallbackWatcher ;
96use Phpactor \AmpFsWatch \Watcher \Find \FindWatcher ;
107use Phpactor \AmpFsWatch \Watcher \FsWatch \FsWatchWatcher ;
118use Phpactor \AmpFsWatch \Watcher \Inotify \InotifyWatcher ;
12- use Phpactor \AmpFsWatch \Watcher \Null \NullWatcher ;
139use Phpactor \AmpFsWatch \Watcher \PatternMatching \PatternMatchingWatcher ;
1410use Phpactor \AmpFsWatch \Watcher \PhpPollWatcher \PhpPollWatcher ;
1511use Psr \Log \AbstractLogger ;
12+ use Revolt \EventLoop ;
1613
1714require __DIR__ . '/../vendor/autoload.php ' ;
1815
1916echo "This is a demo application \n" ;
2017
2118if (!isset ($ argv [1 ])) {
22- echo " You must specify a path to watch " ;
19+ echo ' You must specify a path to watch ' ;
2320 exit (1 );
2421}
25-
22+
2623$ path = $ argv [1 ];
2724$ logger = new class extends AbstractLogger {
28- public function log ($ level , $ message , array $ context = [])
25+ public function log ($ level , $ message , array $ context = []): void
2926 {
30- fwrite (STDERR , sprintf ('[%s] %s ' , $ level , $ message ). "\n" );
27+ fwrite (STDERR , sprintf ('[%s] %s ' , $ level , $ message ) . "\n" );
3128 }
3229};
3330
@@ -40,18 +37,15 @@ $watcher = new PatternMatchingWatcher(new FallbackWatcher([
4037 new FsWatchWatcher ($ config , $ logger ),
4138], $ logger ), [ '/**/*.php ' ], []);
4239
43- Loop::run (function () use ($ watcher , $ path ) {
44- $ process = yield $ watcher ->watch ([$ path ]);
40+ $ process = $ watcher ->watch ();
4541
46- while (null !== $ file = yield $ process ->wait ()) {
47- fwrite (STDOUT , sprintf ('[%s] %s (%s) ' ."\n" , date ('Y-m-d H:i:s.u ' ), $ file ->path (), $ file ->type ()));
48- }
42+ // Signals are not supported on Windows
43+ if (defined ('SIGINT ' )) {
44+ EventLoop::onSignal (SIGINT , function () use ($ process ): void {
45+ $ process ->stop ();
46+ });
47+ }
4948
50- // Signals are not supported on Windows
51- if (defined ('SIGINT ' )) {
52- Loop::onSignal (SIGINT , function () use ($ process ) {
53- $ process ->stop ();
54- Loop::stop ();
55- });
56- }
57- });
49+ while (null !== $ file = $ process ->wait ()) {
50+ fwrite (STDOUT , sprintf ('[%s] %s (%s) ' . "\n" , date ('Y-m-d H:i:s.u ' ), $ file ->path (), $ file ->type ()));
51+ }
0 commit comments