public function main() { $input = new \ezcConsoleInput(); $output = new \ezcConsoleOutput(); $input->registerOption(new \ezcConsoleOption('h', 'help')); $input->registerOption(new \ezcConsoleOption('p', 'process')); $input->process(); if ($input->getOption("p")->value) { $parser = new PHPLpm\Parser(); $result = $parser->parse(file_get_contents("_testdata/sample.php", 1)); $table = new \ezcConsoleTable($output, 60); $table[0][0]->content = "Class"; $table[0][1]->content = "Method"; $table[0][2]->content = "Lines"; $i = 1; foreach ($result as $class => $methods) { foreach ($methods as $method) { $row = $table[$i]; $row[0]->content = $class; $row[1]->content = $method["name"]; $row[2]->content = (string) $method["lines"]; $i++; } } $table->outputTable(); print "\n"; //print_r($result); } }
/** * Generate table output * * @param VcsStats_Table $table Table * @return void */ public function renderTable(VcsStats_Report_Element_Table $table) { $result = ''; $output = new ezcConsoleOutput(); $output->formats->title->style = array('bold'); $alignments = array('center' => ezcConsoleTable::ALIGN_CENTER, 'left' => ezcConsoleTable::ALIGN_LEFT, 'right' => ezcConsoleTable::ALIGN_RIGHT); $consoleTable = new ezcConsoleTable($output, 78); // Display header $consoleTable[0]->align = ezcConsoleTable::ALIGN_CENTER; foreach ($table->getColumns() as $column) { $consoleTable[0][]->content = $column->getTitle(); } // Display values foreach ($table->getRows() as $i => $row) { $j = 0; foreach ($row as $code => $value) { $alignment = $table->getColumn($code)->getAlignment(); $consoleTable[$i + 1][$j]->align = $alignments[$alignment]; $consoleTable[$i + 1][$j]->content = $value; $j++; } } ob_start(); $output->outputLine(); $output->outputLine($table->getTitle(), 'title'); $consoleTable->outputTable(); $output->outputLine(); $output->outputLine(); $result .= ob_get_clean(); echo $result; }
/** * Displays report or generates its files * * @param PHP_ConfigReport_Report $report Report * @return void */ public function render(PHP_ConfigReport_Report $report) { $consoleOutput = new ezcConsoleOutput(); $consoleOutput->formats->extensionName->style = array('bold'); $consoleOutput->formats->columnTitle->style = array('bold'); $consoleOutput->formats->error->bgcolor = 'red'; $consoleOutput->formats->warning->bgcolor = 'yellow'; $consoleOutput->outputLine('PHP version: ' . $report->getPhpVersion()); $consoleOutput->outputLine('Environment: ' . $report->getEnvironment()); $noIssue = true; foreach ($report->getSections() as $section) { if ($section->hasIssues()) { $noIssue = false; $consoleOutput->outputLine(); $consoleOutput->outputLine($section->getExtensionName(), 'extensionName'); $table = new ezcConsoleTable($consoleOutput, $this->_width); $table[0]->format = 'columnTitle'; $table[0][0]->content = 'Directive'; $table[0][1]->content = 'Level'; $table[0][2]->content = 'Type'; $table[0][3]->content = 'Value'; $table[0][4]->content = 'Suggested value'; $table[0][5]->content = 'Comments'; foreach ($section->getIssues() as $index => $issue) { $table[$index + 1]->format = $issue->getLevel(); $directiveName = $issue->getDirectiveName(); if (is_array($directiveName)) { $directiveName = implode(' / ', $directiveName); } $table[$index + 1][0]->content = $directiveName; $table[$index + 1][1]->content = $issue->getLevel(); $table[$index + 1][2]->content = $issue->getType(); $directiveActualValue = $issue->getDirectiveActualValue(); if (is_array($directiveActualValue)) { $directiveActualValue = implode(' / ', $directiveActualValue); } $table[$index + 1][3]->content = $directiveActualValue; $directiveSuggestedValue = $issue->getDirectiveSuggestedValue(); if (is_array($directiveSuggestedValue)) { $directiveSuggestedValue = implode(' / ', $directiveSuggestedValue); } $table[$index + 1][4]->content = $directiveSuggestedValue; $table[$index + 1][5]->content = $issue->getComments(); } $table->outputTable(); $consoleOutput->outputLine(); } } if ($noIssue) { $consoleOutput->outputLine('No issue found.'); $consoleOutput->outputLine(); } }
* @param string $className */ function __autoload($className) { ezcBase::autoload($className); } // Initialize the console output handler $out = new ezcConsoleOutput(); // Define a new format "headline" $out->formats->headline->color = 'red'; $out->formats->headline->style = array('bold'); // Define a new format "sum" $out->formats->sum->color = 'blue'; $out->formats->sum->style = array('negative'); // Create a new table $table = new ezcConsoleTable($out, 60); // Create first row and in it the first cell $table[0][0]->content = 'Headline 1'; // Create 3 more cells in row 0 for ($i = 2; $i < 5; $i++) { $table[0][]->content = "Headline {$i}"; } $data = array(1, 2, 3, 4); // Create some more data in the table... foreach ($data as $value) { // Create a new row each time and set it's contents to the actual value $table[][0]->content = "{$value}"; } // Set another border format for our headline row $table[0]->borderFormat = 'headline'; // Set the content format for all cells of the 3rd row to "sum"
public function testOutputTable() { $table = new ezcConsoleTable($this->output, 80); for ($i = 0; $i < count($this->tableData1); $i++) { for ($j = 0; $j < count($this->tableData1[$i]); $j++) { $table[$i][$j]->content = $this->tableData1[$i][$j]; } } $table[0][0]->format = "red"; $table[0]->borderFormat = "green"; ob_start(); $table->outputTable(); $res = ob_get_clean(); $refFile = dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . 'testTable1a.dat'; $this->assertEquals(file_get_contents($refFile), $res, "Table not printed correctly on use of outputTable()"); }