public function createTable(array $data, $showHeader = true, $columnWidth = array('columnWidths' => array(10, 20))) { $tableConfig = array('columnWidths' => $columnWidth['columnWidths'], 'AutoSeparate' => Zend_Text_Table::AUTO_SEPARATE_ALL, 'padding' => 1); $table = new Zend_Text_Table($tableConfig); if ($showHeader) { $table->appendRow($this->getHeader($data)); } foreach ($data as $row) { $row = $this->cleanArray($row); $table->appendRow($row); } return (string) $table; }
protected function __construct(Zend_Form $form) { $this->setForm($form); $this->setSelectedFields($this->getAllFieldsArray()); //TODO - Auslagern? Zend_Text_Table::setOutputCharset('ISO-8859-1'); $this->setZendTextTable(new Zend_Text_Table(array('columnWidths' => array(20, 50)))); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->detectMagento($output, true); if ($this->initMagento()) { $table = new \Zend_Text_Table(array('columnWidths' => array(8, 30, 60, 60))); $tableData = array(); if ($this->initMagento()) { $time = microtime(true); $rewrites = $this->loadRewrites(); $conflictCounter = 0; foreach ($rewrites as $type => $data) { if (count($data) > 0 && is_array($data)) { foreach ($data as $class => $rewriteClass) { if (count($rewriteClass) > 1) { if ($this->_isInheritanceConflict($rewriteClass)) { $tableData[] = array('Type' => $type, 'Class' => $class, 'Rewrites' => implode(', ', $rewriteClass), 'Loaded Class' => $this->_getLoadedClass($type, $class)); $conflictCounter++; } } } } } if ($input->getOption('log-junit')) { $this->logJUnit($tableData, $input->getOption('log-junit'), microtime($time) - $time); } else { if ($conflictCounter > 0) { array_map(array($table, 'appendRow'), $tableData); $output->write($table->render()); $message = sprintf('%d %s found!', $conflictCounter, $conflictCounter == 1 ? 'conflict was' : 'conflicts were'); $output->writeln('<error>' . $message . '</error>'); } else { $output->writeln('<info>No rewrite conflicts were found.</info>'); } } } } }
/** * Set the output charset for column contents * * @param string $charset */ public static function setOutputCharset($charset) { self::$_outputCharset = strtolower($charset); }
/** * Render the column width the given column width * * @param integer $columnWidth The width of the column * @param integer $padding The padding for the column * @throws Zend_Text_Table_Exception When $columnWidth is lower than 1 * @throws Zend_Text_Table_Exception When padding is greater than columnWidth * @return string */ public function render($columnWidth, $padding = 0) { if (is_int($columnWidth) === false or $columnWidth < 1) { require_once 'Zend/Text/Table/Exception.php'; throw new Zend_Text_Table_Exception('$columnWidth must be an integer and greater than 0'); } $columnWidth -= $padding * 2; if ($columnWidth < 1) { require_once 'Zend/Text/Table/Exception.php'; throw new Zend_Text_Table_Exception('Padding (' . $padding . ') is greater than column width'); } switch ($this->_align) { case self::ALIGN_LEFT: $padMode = STR_PAD_RIGHT; break; case self::ALIGN_CENTER: $padMode = STR_PAD_BOTH; break; case self::ALIGN_RIGHT: $padMode = STR_PAD_LEFT; break; default: // This can never happen, but the CS tells I have to have it ... break; } $outputCharset = Zend_Text_Table::getOutputCharset(); $lines = explode("\n", Zend_Text_MultiByte::wordWrap($this->_content, $columnWidth, "\n", true, $outputCharset)); $paddedLines = array(); foreach ($lines as $line) { $paddedLines[] = str_repeat(' ', $padding) . Zend_Text_MultiByte::strPad($line, $columnWidth, ' ', $padMode, $outputCharset) . str_repeat(' ', $padding); } $result = implode("\n", $paddedLines); return $result; }
public function testTableMagicToString() { $table = new Zend_Text_Table(array('columnWidths' => array(10))); $row = new Zend_Text_Table_Row(); $row->appendColumn(new Zend_Text_Table_Column('foobar')); $table->appendRow($row); $this->assertEquals((string) $table, "┌──────────┐\n│foobar │\n└──────────┘\n"); }
/** * Set the content. * * If $charset is not defined, it is assumed that $content is encoded in * the charset defined via Zend_Text_Table::setInputCharset() (defaults * to utf-8). * * @param string $content Content of the column * @param string $charset The charset of the content * @throws Zend_Text_Table_Exception When $content is not a string * @return Zend_Text_Table_Column */ public function setContent($content, $charset = null) { if (is_string($content) === false) { #require_once 'Zend/Text/Table/Exception.php'; throw new Zend_Text_Table_Exception('$content must be a string'); } if ($charset === null) { $inputCharset = Zend_Text_Table::getInputCharset(); } else { $inputCharset = strtolower($charset); } $outputCharset = Zend_Text_Table::getOutputCharset(); if ($inputCharset !== $outputCharset) { if (PHP_OS != 'AIX') { // AIX does not understand these character sets $content = iconv($inputCharset, $outputCharset, $content); } } $this->_content = $content; return $this; }
/** * Print current DB statistics * * @throws Zend_Text_Table_Exception * * @return void Nothing */ protected function _printStatistics() { echo "============================================================================================================\n"; echo "Current statistics :\n"; $table = new Zend_Text_Table(array('columnWidths' => array(60, 40))); foreach ($this->_statistics as $statisticKey => $value) { $table->appendRow(array($statisticKey, $value)); } echo (string) $table; echo "\n"; }
$document->addField(Zend_Search_Lucene_Field::keyword('audience_type', $result['audience_type'])); $document->addField(Zend_Search_Lucene_Field::keyword('audience_value', $result['event_cohort'])); $document->addField(Zend_Search_Lucene_Field::keyword('event_start', $result['event_start'])); $document->addField(Zend_Search_Lucene_Field::unStored('files_body', $filesBody)); $document->addField(Zend_Search_Lucene_Field::keyword('organisation_id', $result['organisation_id'])); $index->addDocument($document); } break; case 'optimize': $index = Zend_Search_Lucene::open($path . '/' . $input->index); $index->optimize(); break; case 'search': $index = Zend_Search_Lucene::open($path . '/' . $input->index); $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($input->term); $results = $index->find($userQuery); $textTable = new Zend_Text_Table(array('columnWidths' => array(12, 12, 5, 45))); $textTable->appendRow(array('Document ID', 'Database ID', 'Score', 'Title')); foreach ($results as $hit) { $textTable->appendRow(array((string) $hit->id, (string) $hit->event_id, (string) round($hit->score, 2), $hit->title)); } echo $textTable; break; case 'status': $index = Zend_Search_Lucene::open($path . '/' . $input->index); $textTable = new Zend_Text_Table(array('columnWidths' => array(30, 10))); $textTable->appendRow(array('Documents Count', (string) $index->count())); $textTable->appendRow(array('Non-deleted Documents Count', (string) $index->numDocs())); echo $textTable; break; }
<?php set_include_path('/var/www/zend-framework-1.7.2/library:.'); require_once 'Zend/Text/Table.php'; require_once 'Zend/Text/Table/Column.php'; $options = array('columnWidths' => array(20, 20)); $table = new Zend_Text_Table($options); $table->appendRow(array('Ete', 'Dummy')); $table->appendRow(array('Eté', 'Dummy')); echo '<pre>' . $table . '</pre>';
public function logprofiler($action) { $suiteLogPath = Mage::getBaseDir('var') . DS . 'log' . DS . 'SagePaySuite'; $profilerPath = $suiteLogPath . DS . 'PROFILER'; if (!is_dir($suiteLogPath)) { mkdir($suiteLogPath, 0755); } if (!is_dir($profilerPath)) { mkdir($profilerPath, 0755); } $timers = Varien_Profiler::getTimers(); $request = $action->getRequest(); $prefix = $request->getParam('vtxcode', $request->getParam('VPSTxId', null)); $prefix = $prefix ? $prefix . '_' : ''; $longest = 0; $rows = array(); foreach ($timers as $name => $timer) { $sum = Varien_Profiler::fetch($name, 'sum'); $count = Varien_Profiler::fetch($name, 'count'); $realmem = Varien_Profiler::fetch($name, 'realmem'); $emalloc = Varien_Profiler::fetch($name, 'emalloc'); if ($sum < 0.001 && $count < 10 && $emalloc < 10000) { continue; } $rows[] = array((string) $name, (string) number_format($sum, 4), (string) $count, (string) number_format($emalloc), (string) number_format($realmem)); $thislong = strlen($name); if ($thislong > $longest) { $longest = $thislong; } } //Create table $table = new Zend_Text_Table(array('columnWidths' => array($longest, 10, 6, 12, 12), 'decorator' => 'ascii')); //Memory $preheader = new Zend_Text_Table_Row(); $real = memory_get_usage(true); $emalloc = memory_get_usage(); $preheader->appendColumn(new Zend_Text_Table_Column('real Memory usage: ' . $real . ' ' . ceil($real / 1048576) . 'MB', 'center', 1)); $preheader->appendColumn(new Zend_Text_Table_Column('emalloc Memory usage: ' . $emalloc . ' ' . ceil($emalloc / 1048576) . 'MB', 'center', 4)); $table->appendRow($preheader); //Append Header $header = new Zend_Text_Table_Row(); $header->appendColumn(new Zend_Text_Table_Column('Code Profiler', 'center')); $header->appendColumn(new Zend_Text_Table_Column('Time', 'center')); $header->appendColumn(new Zend_Text_Table_Column('Cnt', 'center')); $header->appendColumn(new Zend_Text_Table_Column('Emalloc', 'center')); $header->appendColumn(new Zend_Text_Table_Column('RealMem', 'center')); $table->appendRow($header); foreach ($rows as $row) { $table->appendRow($row); } //SQL profile $dbprofile = print_r(Varien_Profiler::getSqlProfiler(Mage::getSingleton('core/resource')->getConnection('core_write')), TRUE); $dbprofile = substr($dbprofile, 0, -4); $dbprofile = str_replace('<br>', "\n", $dbprofile); $preheaderlabel = new Zend_Text_Table_Row(); $preheaderlabel->appendColumn(new Zend_Text_Table_Column('DATABASE', 'center', 5)); $table->appendRow($preheaderlabel); $preheader = new Zend_Text_Table_Row(); $preheader->appendColumn(new Zend_Text_Table_Column($dbprofile, 'left', 5)); $table->appendRow($preheader); //Request $rqlabel = new Zend_Text_Table_Row(); $rqlabel->appendColumn(new Zend_Text_Table_Column('REQUEST', 'center', 5)); $table->appendRow($rqlabel); $inforqp = new Zend_Text_Table_Row(); $inforqp->appendColumn(new Zend_Text_Table_Column($this->_filterRequest($request), 'left', 5)); $table->appendRow($inforqp); $date = Mage::getModel('core/date')->date('Y-m-d\\.H-i-s'); $file = new SplFileObject($profilerPath . DS . $prefix . $date . '_' . $action->getFullActionName() . '.txt', 'w'); $file->fwrite($table); }
protected function _renderInfoTable() { $table = new Zend_Text_Table(array('columnWidths' => array(15, 15, 13, 15, 20, 18, 20, 13))); $headerRow = array('Parent Id', 'Children Ids', '[C] Grouped Simple Links', '[X] Super Links', '[X] Super Attribute', '[X] Custom Options', '[X] Attribute Values', '[C] Positions'); $linesCounter = 0; foreach ($this->_processedProducts as $data) { if (0 == $linesCounter % 20) { //Append Header on 0 and every 20 lines $table->appendRow($headerRow); } $row = new Zend_Text_Table_Row(); foreach ($data as $value) { $value = is_array($value) ? implode(',', $value) : (string) $value; $row->appendColumn(new Zend_Text_Table_Column($value)); } $table->appendRow($row); $linesCounter++; } echo $table; }