Exemplo n.º 1
0
Arquivo: Runner.php Projeto: gsouf/pho
 /**
  * Monitors the the current working directory for modifications, and reruns
  * the specs in another process on change.
  */
 public function watch()
 {
     $watcher = new Watcher();
     $watcher->watchPath(getcwd());
     $watcher->addListener(function () {
         $paths = implode(' ', self::$console->getPaths());
         $descriptor = [0 => ['pipe', 'r'], 1 => ['pipe', 'w']];
         // Rebuild option string, without watch
         $optionString = '';
         foreach (self::$console->options as $key => $val) {
             if ($key == 'watch') {
                 continue;
             } elseif ($val === true) {
                 // test
                 $optionString .= "--{$key} ";
             } elseif ($val) {
                 $optionString .= "--{$key} {$val} ";
             }
         }
         // Run pho in another process and echo its stdout
         $procStr = "{$_SERVER['SCRIPT_FILENAME']} {$optionString} {$paths}";
         $process = proc_open($procStr, $descriptor, $pipes);
         if (is_resource($process)) {
             while ($buffer = fread($pipes[1], 16)) {
                 self::$console->write($buffer);
             }
             fclose($pipes[0]);
             fclose($pipes[1]);
             proc_close($process);
         }
     });
     // Ever vigilant
     $watcher->watch();
 }
Exemplo n.º 2
0
 /**
  * Monitors the the current working directory for modifications, and reruns
  * the specs in another process on change.
  */
 public function watch()
 {
     $watcher = new Watcher();
     $watcher->watchPath(getcwd());
     $class = get_class();
     $watcher->addListener(function () use($class) {
         $paths = implode(' ', $class::$console->getPaths());
         $descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
         // Rebuild option string, without watch
         $optionString = '';
         foreach ($class::$console->options as $key => $val) {
             if ($key == 'watch') {
                 continue;
             } elseif ($val === true) {
                 // test
                 $optionString .= "--{$key} ";
             } elseif ($val) {
                 $optionString .= "--{$key} {$val} ";
             }
         }
         // Run pho in another process and echo its stdout
         $process = proc_open("pho {$optionString} {$paths}", $descriptor, $pipes);
         if (is_resource($process)) {
             while ($buffer = fread($pipes[1], 16)) {
                 $class::$console->write($buffer);
             }
             fclose($pipes[0]);
             fclose($pipes[1]);
             proc_close($process);
         }
     });
     // Ever vigilant
     $watcher->watch();
 }