LazyRecord\Schema\Comparator\ConsolePrinter::output PHP Метод

output() публичный Метод

public output ( )
    public function output()
    {
        if (empty($this->diff)) {
            return;
        }
        $formatter = new Formatter();
        echo $formatter->format('--- ' . $this->beforeName, 'strong_white'), "\n";
        echo $formatter->format('+++ ' . $this->afterName, 'strong_white'), "\n";
        echo "@@ columns @@\n";
        foreach ($this->diff as $d) {
            // for each diff items, show attribute diff
            switch ($d->flag) {
                case 'M':
                    echo $formatter->format('M ' . $d->name, 'yellow'), "\n";
                    foreach ($d->details as $attrDiff) {
                        echo "\t" . $formatter->format($attrDiff->getBeforeDescription(), 'red');
                        echo "\t" . $formatter->format($attrDiff->getAfterDescription(), 'green');
                    }
                    break;
                case 'A':
                    $line = $d->toColumnAttrsString();
                    echo $formatter->format($line . "\n", 'green');
                    break;
                case 'D':
                    $line = $d->toColumnAttrsString();
                    echo $formatter->format($line . "\n", 'red');
                    break;
            }
        }
    }

Usage Example

Пример #1
0
 public function execute()
 {
     $formatter = new \CLIFramework\Formatter();
     $options = $this->options;
     $logger = $this->logger;
     $connectionManager = \LazyRecord\ConnectionManager::getInstance();
     $dsId = $this->getCurrentDataSourceId();
     $conn = $connectionManager->getConnection($dsId);
     $driver = $connectionManager->getQueryDriver($dsId);
     $this->logger->info('Performing Comparison...');
     $parser = TableParser::create($driver, $conn);
     $existingTables = $parser->getTables();
     $tableSchemas = $parser->getDeclareSchemaMap();
     $found = false;
     $comparator = new Comparator();
     foreach ($tableSchemas as $table => $currentSchema) {
         $this->logger->debug("Checking table {$table}");
         $ref = new ReflectionObject($currentSchema);
         $filepath = $ref->getFilename();
         $filepath = substr($filepath, strlen(getcwd()) + 1);
         if (in_array($table, $existingTables)) {
             $before = $parser->reverseTableSchema($table);
             $diffs = $comparator->compare($before, $currentSchema);
             if (count($diffs)) {
                 $found = true;
                 $printer = new ComparatorConsolePrinter($diffs);
                 $printer->beforeName = $table . ":data source [{$dsId}]";
                 $printer->afterName = $table . ':' . $filepath;
                 $printer->output();
             }
         } else {
             $msg = sprintf("+ table %-20s %s", "'" . $table . "'", $filepath);
             echo $formatter->format($msg, 'green'), "\n";
             $a = isset($tableSchemas[$table]) ? $tableSchemas[$table] : null;
             $diff = $comparator->compare(new DeclareSchema(), $currentSchema);
             foreach ($diff as $diffItem) {
                 echo "  ", $diffItem->toColumnAttrsString(), "\n";
             }
             $found = true;
         }
     }
     if (!$found) {
         $this->logger->info("No diff found");
     }
 }
ConsolePrinter