ConsoleKit\Widgets\Checklist::run PHP Method

run() public method

public run ( array $steps )
$steps array
    public function run(array $steps)
    {
        $maxMessageLength = min(array_reduce(array_keys($steps), function ($r, $i) {
            return max(strlen($i), $r);
        }, 0), $this->maxMessageLength);
        foreach ($steps as $message => $callback) {
            $this->step($message, $callback, $maxMessageLength);
        }
    }

Usage Example

コード例 #1
0
ファイル: UpdateCommand.php プロジェクト: jasny/dbvc
 /**
  * Run a list of updates
  * 
  * @param array $files
  */
 protected function runUpdates(array $files)
 {
     $steps = array();
     $config = $this->dbvc()->config;
     $checklist = new Checklist($this->getConsole()->getTextWriter());
     $db = $this->dbvc()->db();
     $this->writeln("Running updates for database '{$config->db->dbname}':", Colors::YELLOW);
     foreach ($files as $update => $file) {
         $file = $config->datadir . DIRECTORY_SEPARATOR . 'updates' . DIRECTORY_SEPARATOR . $file;
         $message = "  {$update} ";
         if ($this->force) {
             $steps[$message] = function () use($db, $update, $file) {
                 try {
                     $db->run($file);
                 } catch (\Exception $e) {
                     return false;
                 }
                 $db->markUpdate($update);
                 return true;
             };
         } else {
             $steps[$message] = function () use($db, $update, $file) {
                 $db->run($file);
                 $db->markUpdate($update);
                 return true;
             };
         }
     }
     $checklist->run($steps);
 }