12
12
13
13
namespace PatternLab \Reload ;
14
14
15
- use \Cocur \BackgroundProcess \BackgroundProcess ;
16
15
use \PatternLab \Config ;
17
16
use \PatternLab \Console ;
17
+ use \PatternLab \Console \ProcessSpawnerEvent ;
18
18
use \PatternLab \Data ;
19
19
20
20
class PatternLabListener extends \PatternLab \Listener {
@@ -25,20 +25,32 @@ class PatternLabListener extends \PatternLab\Listener {
25
25
public function __construct () {
26
26
27
27
// add listener
28
- $ this ->addListener ("watcher.start " ,"initServer " );
28
+ $ this ->addListener ("processSpawner.getPluginProcesses " ,"addProcess " );
29
29
30
30
}
31
31
32
32
/**
33
- * Initialize the web socket server
33
+ * Add command to initialize the websocket server
34
34
*/
35
- public function initServer ( ) {
35
+ public function addProcess ( ProcessSpawnerEvent $ event ) {
36
36
37
37
if ((bool )Config::getOption ("reload.on " )) {
38
- $ php = isset ($ _SERVER ["_ " ]) ? $ _SERVER ["_ " ] : Config::getOption ("phpBin " );
39
- $ path = __DIR__ ."/AutoReloadServer.php " ;
40
- $ process = new BackgroundProcess ($ php ." " .$ path );
41
- $ process ->run ();
38
+
39
+ // only run this command if watch is going to be used
40
+ if (Console::findCommand ("w|watch " ) || Console::findCommandOption ("with-watch " )) {
41
+
42
+ // set-up the command
43
+ $ pathPHP = Console::getPathPHP ();
44
+ $ pathReload = __DIR__ ."/AutoReloadServer.php " ;
45
+ $ command = "exec " .$ pathPHP ." " .$ pathReload ;
46
+
47
+ // send the processes on their way
48
+ $ processes = array ();
49
+ $ processes [] = array ("command " => $ command , "timeout " => null , "idle " => 600 , "output " => false );
50
+ $ event ->addPluginProcesses ($ processes );
51
+
52
+ }
53
+
42
54
}
43
55
44
56
}
0 commit comments