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("[30mHello world!")); $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">Hello world!</span>', $converter->parse("[30;1mHello world!")); $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">"Hello world!"</span>', $converter->parse("[30;1m\"Hello world!\"")); $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">"Hello Dude!"</span>', $converter->parse("[30;1m\"Hello worldDude!\"")); $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">"Hello?"</span>', $converter->parse("[30;1m\"Hello worldDude!?\"")); $this->assertEquals('<span style="color: rgba(0,0,0,1);font-weight: bold;">"Hello..."</span>', $converter->parse("[30;1m\"Hello worldDu\nde!...\"")); $input = "[32mLoading composer repositories with package information[39m\n[32mUpdating dependencies[39m\n - Removing [32mtest/testpackage[39m ([33m1.7[39m)\n - Installing [32mtest/testpackage[39m ([33m1.8.1[39m)\n Downloading\n\n - installed [32m2[39m files\n[32mWriting lock file[39m\n[32mGenerating autoload files[39m"; $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)); }
/** * {@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&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(); } }
/** * {@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&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(); } }