Exemplo n.º 1
0
 /**
  * Tail a log file
  *
  * If more than one log file exists, will display a menu dialog with a list
  * of log files to choose from.
  */
 protected function tail()
 {
     $logs = array();
     $i = 1;
     $workers = (array) $this->getWorkers();
     foreach ($workers as $worker) {
         if ($worker['Log']['filename'] != '') {
             $logs[] = $worker['Log']['filename'];
         }
         if ($worker['Log']['handler'] == 'RotatingFile') {
             $fileInfo = pathinfo($worker['Log']['target']);
             $pattern = $fileInfo['dirname'] . DS . $fileInfo['filename'] . '-*' . (!empty($fileInfo['extension']) ? '.' . $fileInfo['extension'] : '');
             $logs = array_merge($logs, glob($pattern));
         }
     }
     $logs = array_values(array_unique($logs));
     $this->outputTitle('Tailing log file');
     if (empty($logs)) {
         $this->output->outputLine('No log file to tail', 'failure');
         return;
     } elseif (count($logs) == 1) {
         $index = 1;
     } else {
         $menuOptions = new \ezcConsoleMenuDialogOptions(array('text' => 'Log files list', 'selectText' => 'Log to tail :', 'validator' => new DialogMenuValidator(array_combine(range(1, count($logs)), $logs))));
         $menuDialog = new \ezcConsoleMenuDialog($this->output, $menuOptions);
         do {
             $menuDialog->display();
         } while ($menuDialog->hasValidResult() === false);
         $index = $menuDialog->getResult();
     }
     $this->output->outputLine('Tailing ' . $logs[$index - 1], 'subtitle');
     passthru('tail -f ' . escapeshellarg($logs[$index - 1]));
 }
Exemplo n.º 2
0
 /**
  * Display a Dialog menu, and retrieve the user selection
  *
  * @param  string $listTitle     Title of the menu dialog
  * @param  string $selectMessage Select option message
  * @param  array  $menuItems     The menu contents
  *
  * @codeCoverageIgnore
  * @since  1.2.0
  * @return int The index in the menu that was selected
  */
 protected function getUserChoice($listTitle, $selectMessage, $menuItems)
 {
     $menuOptions = new \ezcConsoleMenuDialogOptions(array('text' => $listTitle, 'selectText' => $selectMessage, 'validator' => new DialogMenuValidator($menuItems)));
     $menuDialog = new \ezcConsoleMenuDialog($this->output, $menuOptions);
     do {
         $menuDialog->display();
     } while ($menuDialog->hasValidResult() === false);
     return $menuDialog->getResult();
 }
Exemplo n.º 3
0
 public function testBasicMethods()
 {
     $output = new ezcConsoleOutput();
     $dialog = new ezcConsoleMenuDialog($output);
     $this->assertFalse($dialog->hasValidResult(), "Fresh dialog has valid result.");
     $exceptionCaught = false;
     try {
         $dialog->getResult();
     } catch (ezcConsoleNoValidDialogResultException $e) {
         $exceptionCaught = true;
     }
     $this->assertTrue($exceptionCaught, "Excption not thrown on getResult() without result.");
     $dialog->reset();
     $exceptionCaught = false;
     try {
         $dialog->getResult();
     } catch (ezcConsoleNoValidDialogResultException $e) {
         $exceptionCaught = true;
     }
     $this->assertTrue($exceptionCaught, "Excption not thrown on getResult() without result.");
 }