This class is used to send the output easier
Since: 0.1
Author: Rafael Reis @reisraff
コード例 #1
0
ファイル: Sender.php プロジェクト: gabrielrcouto/php-gui
 /**
  * Print debug information
  *
  * @param String $text Text to print
  *
  * @return void
  */
 protected function out($text)
 {
     if ($this->application->getVerboseLevel() == 2) {
         $re = explode('}{', $text);
         foreach ($re as $key => $value) {
             if (count($re) > 1 && $key == 0) {
                 Output::out('=> Sent: ' . $value . '}', 'yellow');
             } elseif (count($re) > 1 && $key == count($re) - 1) {
                 Output::out('=> Sent: {' . $value, 'yellow');
             } elseif (count($re) > 1) {
                 Output::out('=> Sent: {' . $value . '}', 'yellow');
             } else {
                 Output::out('=> Sent: ' . $value, 'yellow');
             }
         }
     }
 }
コード例 #2
0
ファイル: Receiver.php プロジェクト: gabrielrcouto/php-gui
 /**
  * Parse a debug message
  *
  * @param $message Message
  *
  * @return void
  */
 protected function parseDebug($message)
 {
     if ($this->application->getVerboseLevel() == 2) {
         Output::out('<= Debug: ' . json_encode($message), 'blue');
     }
 }
コード例 #3
0
ファイル: Application.php プロジェクト: gabrielrcouto/php-gui
 /**
  * Runs the application
  *
  * @return void
  */
 public function run()
 {
     if (!self::$defaultApplication) {
         self::$defaultApplication = $this;
     }
     $application = $this;
     if (OsDetector::isMacOS()) {
         $processName = './phpgui-i386-darwin';
         $processPath = __DIR__ . '/../lazarus/phpgui-i386-darwin.app/Contents/MacOS/';
     } elseif (OsDetector::isFreeBSD()) {
         $processName = './phpgui-x86_64-freebsd';
         $processPath = __DIR__ . '/../lazarus/';
     } elseif (OsDetector::isUnix()) {
         $processName = './phpgui-x86_64-linux';
         $processPath = __DIR__ . '/../lazarus/';
     } elseif (OsDetector::isWindows()) {
         $processName = '.\\phpgui-x86_64-win64';
         $processPath = __DIR__ . '\\..\\lazarus\\';
     } else {
         throw new RuntimeException('Operational System not identified by PHP-GUI.');
     }
     $this->process = $process = new Process($processName, $processPath);
     $this->process->on('exit', function () use($application) {
         $application->loop->stop();
     });
     $this->receiver = $receiver = new Receiver($this);
     $this->sender = $sender = new Sender($this, $receiver);
     $this->loop->addTimer(0.001, function ($timer) use($process, $application, $receiver) {
         $process->start($timer->getLoop());
         // We need to pause all default streams
         // The react/loop uses fread to read data from streams
         // On Windows, fread always is blocking
         // Stdin is paused, we use our own way to write on it
         $process->stdin->pause();
         // Stdout is paused, we use our own way to read it
         $process->stdout->pause();
         // Stderr is paused for avoiding fread
         $process->stderr->pause();
         $process->stdout->on('data', function ($data) use($receiver) {
             $receiver->onData($data);
         });
         $process->stderr->on('data', function ($data) {
             if (!empty($data)) {
                 Output::err($data);
             }
         });
         $application->running = true;
         // Bootstrap the application
         $application->fire('start');
     });
     $this->loop->addPeriodicTimer(0.001, function () use($application) {
         $application->sender->tick();
         if (@is_resource($application->process->stdout->stream)) {
             $application->receiver->tick();
         }
     });
     $this->loop->run();
 }