1212
1313namespace PatternLab \Reload ;
1414
15- use \Cocur \BackgroundProcess \BackgroundProcess ;
1615use \PatternLab \Config ;
1716use \PatternLab \Console ;
17+ use \PatternLab \Console \ProcessSpawnerEvent ;
1818use \PatternLab \Data ;
1919
2020class PatternLabListener extends \PatternLab \Listener {
@@ -25,20 +25,32 @@ class PatternLabListener extends \PatternLab\Listener {
2525 public function __construct () {
2626
2727 // add listener
28- $ this ->addListener ("watcher.start " ,"initServer " );
28+ $ this ->addListener ("processSpawner.getPluginProcesses " ,"addProcess " );
2929
3030 }
3131
3232 /**
33- * Initialize the web socket server
33+ * Add command to initialize the websocket server
3434 */
35- public function initServer ( ) {
35+ public function addProcess ( ProcessSpawnerEvent $ event ) {
3636
3737 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+
4254 }
4355
4456 }
0 commit comments