confirm() public method

Returns true if it matches $expected, false otherwise if($dialog->confirm('Are you sure?')) { ... } if($dialog->confirm('Your choice?', null, array('a', 'b', 'c'))) { ... }
public confirm ( string $text, string $expected = 'y', array $choices = ['Y', 'n'], string $default = 'y', string $errorMessage = 'Invalid choice' ) : boolean
$text string
$expected string
$choices array
$default string
$errorMessage string
return boolean
Exemplo n.º 1
0
 public function executeImport(array $args = array(), array $options = array())
 {
     $databases = $this->getConfig('$.mysql.databases');
     if (isset($args[0]) && !isset($args[1]) && !empty($databases)) {
         if (count($databases) == 1) {
             $databases = array($databases[0] => $args[0]);
         } else {
             $dialog = new ConsoleKit\Widgets\Dialog($this->getConsole());
             $choice = $dialog->ask("Choose a database :\n- " . implode("\n- ", $databases) . "\nEnter a database name:", $databases[0]);
             $databases = array($choice => $args[0]);
         }
     } else {
         if (isset($args[0]) && isset($args[1])) {
             $databases = array($args[1] => $args[0]);
         } else {
             $databases = array();
         }
     }
     if (!empty($databases)) {
         foreach ($databases as $database => $file) {
             if (!file_exists($file)) {
                 $this->writeln('File ' . $file . ' does not exist', ConsoleKit\Colors::YELLOW);
             } else {
                 if (empty($database)) {
                     $this->writeln('No database set', ConsoleKit\Colors::YELLOW);
                 } else {
                     $dialog = new ConsoleKit\Widgets\Dialog($this->getConsole());
                     if ($dialog->confirm('Are you sure you want to import ' . $file . ' into ' . $database . ' ?')) {
                         $running = true;
                         if (!($running = $this->isRunning($this->getPath($options['pid-file'])))) {
                             $this->getConsole()->execute('mysql', array('daemon', 'start'), $options);
                         }
                         exec($this->getConfig('$.mysql.commands.mysql') . ' --user=root --password="******" ' . $this->buildParameters($options, 'socket') . ' ' . $database . ' < ' . $file);
                         if (!$running) {
                             $this->getConsole()->execute('mysql', array('daemon', 'stop'), $options);
                         }
                         $this->writeln('File ' . $file . ' imported to ' . $database, ConsoleKit\Colors::GREEN);
                     }
                 }
             }
         }
     } else {
         $this->writeln('Missing arguments', ConsoleKit\Colors::YELLOW);
     }
 }