예제 #1
0
 public static function dumpRows(array $array, array $options = array())
 {
     $table = new Table();
     $keys = null;
     if (isset($options['keys'])) {
         $keys = $options['keys'];
     } else {
         if (isset($array[0])) {
             $keys = array_keys($array[0]);
         }
     }
     if ($keys) {
         $table->setHeaders($keys);
     }
     if (empty($array)) {
         return '0 rows.' . PHP_EOL;
     }
     foreach ($array as $item) {
         $values = [];
         foreach ($keys as $key) {
             $values[] = $item[$key];
         }
         $table->addRow($values);
     }
     return $table->render() . PHP_EOL . count($array) . ' rows.' . PHP_EOL;
 }
예제 #2
0
 protected function displayRows(array $rows)
 {
     if (count($rows)) {
         $table = new Table();
         $headers = array_keys($rows[0]);
         $table->setHeaders($headers);
         foreach ($rows as $row) {
             $table->addRow(array_values($row));
         }
         echo $table->render();
     }
 }
예제 #3
0
function dumpQuery($dbh, $query)
{
    $stm = $dbh->query($query);
    if ($stm == false) {
        var_dump($dbh->errorInfo());
        return;
    }
    echo "Result for: {$query}\n";
    $rows = $stm->fetchAll(PDO::FETCH_ASSOC);
    $table = new Table();
    $table->setHeaders(array_keys($rows[0]));
    foreach ($rows as $row) {
        $values = array_map(function ($val) {
            return var_export($val, true);
        }, array_values($row));
        $table->addRow($values);
    }
    echo $table->render();
}
예제 #4
0
<?php

require 'vendor/autoload.php';
use CLIFramework\Component\Table\Table;
$table = new Table();
$table->setHeaders(['Published Date', 'Title', 'Description']);
$table->addRow(array("September 16, 2014", "Zero to One: Notes on Startups, or How to Build the Future", "If you want to build a better future, you must believe in secrets.\n    The great secret of our time is that there are still uncharted frontiers to explore and new inventions to create. In Zero to One, legendary entrepreneur and investor Peter Thiel shows how we can find singular ways to create those new things. ", 29.5));
$table->addRow(array("November 4, 2014", "Hooked: How to Build Habit-Forming Products", ["Why do some products capture widespread attention while others flop? What makes us engage with certain products out of sheer habit? Is there a pattern underlying how technologies hook us? ", "Nir Eyal answers these questions (and many more) by explaining the Hook Model—a four-step process embedded into the products of many successful companies to subtly encourage customer behavior. Through consecutive “hook cycles,” these products reach their ultimate goal of bringing users back again and again without depending on costly advertising or aggressive messaging."], 99));
echo $table->render();