コード例 #1
0
 public function testConverter()
 {
     $converter = new ConsoleColorConverter();
     $this->assertEquals('Hello world!', $converter->parse("Hello world!"));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);">Hello world!</span>', $converter->parse("Hello world!"));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">Hello world!</span>', $converter->parse("Hello world!"));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">&quot;Hello world!&quot;</span>', $converter->parse("\"Hello world!\""));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">&quot;Hello Dude!&quot;</span>', $converter->parse("\"Hello worldDude!\""));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">&quot;Hello?&quot;</span>', $converter->parse("\"Hello worldDude!?\""));
     $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">&quot;Hello...&quot;</span>', $converter->parse("\"Hello worldDu\nde!...\""));
     $input = "Loading composer repositories with package information\nUpdating dependencies\n  - Removing test/testpackage (1.7)\n  - Installing test/testpackage (1.8.1)\n    Downloading\n\n  - installed 2 files\nWriting lock file\nGenerating autoload files";
     $output = '<span style="color: rgba(0,170,0,1);">Loading composer repositories with package information</span><br />' . '<span style="color: rgba(0,170,0,1);">Updating dependencies</span><br />' . '  - Removing <span style="color: rgba(0,170,0,1);">test/testpackage</span> (<span style="color: rgba(170,85,0,1);">1.7</span>)<br />' . '  - Installing <span style="color: rgba(0,170,0,1);">test/testpackage</span> (<span style="color: rgba(170,85,0,1);">1.8.1</span>)<br />' . '    Downloading<br />' . '<br />' . '  - installed <span style="color: rgba(0,170,0,1);">2</span> files<br />' . '<span style="color: rgba(0,170,0,1);">Writing lock file</span><br />' . '<span style="color: rgba(0,170,0,1);">Generating autoload files</span>';
     $this->assertEquals($output, $converter->parse($input));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $outFile = new \File(self::OUT_FILE_PATHNAME);
     $pidFile = new \File(self::PID_FILE_PATHNAME);
     $output = $outFile->getContent();
     $pid = $pidFile->getContent();
     // We send special signal 0 to test for existance of the process which is much more bullet proof than
     // using anything like shell_exec() wrapped ps/pgrep magic (which is not available on all systems).
     $isRunning = (bool) posix_kill($pid, 0);
     $startTime = new \DateTime();
     $startTime->setTimestamp(filectime(TL_ROOT . '/' . self::PID_FILE_PATHNAME));
     $endTime = new \DateTime();
     $endTime->setTimestamp($isRunning ? time() : filemtime(TL_ROOT . '/' . self::OUT_FILE_PATHNAME));
     $uptime = $endTime->diff($startTime);
     $uptime = $uptime->format('%h h %I m %S s');
     if (!$isRunning && \Input::getInstance()->post('close')) {
         $outFile->renameTo(UpdatePackagesController::OUTPUT_FILE_PATHNAME);
         $pidFile->delete();
         $this->redirect('contao/main.php?do=composer&amp;update=database');
     } else {
         if ($isRunning && \Input::getInstance()->post('terminate')) {
             posix_kill($pid, SIGTERM);
             $this->reload();
         }
     }
     $converter = new ConsoleColorConverter();
     $output = $converter->parse($output);
     if (\Environment::getInstance()->isAjaxRequest) {
         header('Content-Type: application/json; charset=utf-8');
         echo json_encode(array('output' => $output, 'isRunning' => $isRunning, 'uptime' => $uptime));
         exit;
     } else {
         $template = new \BackendTemplate('be_composer_client_detached');
         $template->output = $output;
         $template->isRunning = $isRunning;
         $template->uptime = $uptime;
         return $template->parse();
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $outFile = new \File(self::OUT_FILE_PATHNAME);
     $pidFile = new \File(self::PID_FILE_PATHNAME);
     $output = $outFile->getContent();
     $pid = $pidFile->getContent();
     $isRunning = $this->isPidStillRunning($pid);
     $startTime = new \DateTime();
     $startTime->setTimestamp(filectime(TL_ROOT . '/' . self::PID_FILE_PATHNAME));
     $endTime = new \DateTime();
     $endTime->setTimestamp($isRunning ? time() : filemtime(TL_ROOT . '/' . self::OUT_FILE_PATHNAME));
     $uptime = $endTime->diff($startTime);
     $uptime = $uptime->format('%h h %I m %S s');
     if (!$isRunning && \Input::getInstance()->post('close')) {
         $outFile->renameTo(UpdatePackagesController::OUTPUT_FILE_PATHNAME);
         $pidFile->delete();
         $this->redirect('contao/main.php?do=composer&amp;update=database');
     } else {
         if ($isRunning && \Input::getInstance()->post('terminate')) {
             $this->killPid($pid);
             $this->reload();
         }
     }
     $converter = new ConsoleColorConverter();
     $output = $converter->parse($output);
     if (\Environment::getInstance()->isAjaxRequest) {
         header('Content-Type: application/json; charset=utf-8');
         echo json_encode(array('output' => $output, 'isRunning' => $isRunning, 'uptime' => $uptime));
         exit;
     } else {
         $template = new \BackendTemplate('be_composer_client_detached');
         $template->output = $output;
         $template->isRunning = $isRunning;
         $template->uptime = $uptime;
         return $template->parse();
     }
 }