/** * List bundles * * @return void */ private function execList() { $pathArg = $this->getPathArgument('path', false, $this->getCommand()); $path = new ProjectPath($pathArg); $que = $this->getBundleParam(); // user searches for a certain bundle $bundles = $this->service->setProjectPath($path)->getBundles($this->getTypeParam(), $this->getBundleParam()); $this->out("Located project folder: {$path->get()}\n"); if (is_dir($path->get()) === false) { throw new \Exception("No project found at {$pathArg}"); } $tbl = new ConsoleTable(); $tbl->setHeaders(array('S', 'Id', 'Version', 'Author', 'Description')); foreach ($bundles as $bundle) { if (isset($bundle['hide']) && $bundle['hide'] == true) { continue; } $tbl->addRow(array($this->service->getRegistryContainer()->isInstalled($bundle['id']) ? 'i' : 'p', $bundle['id'], $bundle['version'], $bundle['author'], $bundle['description'])); } if (strlen($que)) { // hi-light search results $callback = array($this, 'highlightSearchTerm'); $tbl->addFilter(1, $callback); $this->out(sprintf("Search bundles having \"%s\"..", $que)); } $tbl->setAlign(3, CONSOLE_TABLE_ALIGN_CENTER); $this->out($tbl->getTable()); }
/** * Display final results * * Display final results, when data source parsing is over. * * @access public * @return void * @since version 1.8.0b3 (2008-06-07) */ function display() { $o = $this->args['output-level']; $info = $this->parseData; $hdr = array(); $src = $this->_parser->dataSource; if (isset($this->args['dir'])) { $dir = $this->args['dir']; $hdr[] = 'Files'; } elseif (isset($this->args['file'])) { $file = $this->args['file']; $hdr[] = 'File'; } elseif (isset($this->args['string'])) { $string = $this->args['string']; $hdr[] = 'Source code'; } elseif ($src['dataType'] == 'directory') { $dir = $src['dataSource']; $hdr[] = 'Files'; } elseif ($src['dataType'] == 'file') { $file = $src['dataSource']; $hdr[] = 'File'; } else { $string = $src['dataSource']; $hdr[] = 'Source code'; } $table = new Console_Table(); $f = 0; if ($o & 16) { $hdr[] = 'Version'; $f++; } if ($o & 1) { $hdr[] = 'C'; $f++; } if ($o & 2) { $hdr[] = 'Extensions'; $filter2 = array(&$this, '_splitExtname'); $table->addFilter($f + 1, $filter2); $f++; } if ($o & 4) { if ($o & 8) { $hdr[] = 'Constants/Tokens'; } else { $hdr[] = 'Constants'; } $f++; } else { if ($o & 8) { $hdr[] = 'Tokens'; $f++; } } $table->setHeaders($hdr); $filter0 = array(&$this, '_splitFilename'); $table->addFilter(0, $filter0); if ($o > 3 && $o < 16 || $o > 19) { $filter3 = array(&$this, '_splitConstant'); $table->addFilter($f, $filter3); } $ext = implode("\r\n", $info['extensions']); $const = implode("\r\n", array_merge($info['constants'], $info['tokens'])); if (isset($dir)) { $ds = DIRECTORY_SEPARATOR; $dir = str_replace(array('\\', '/'), $ds, $dir); $data = array($dir . $ds . '*'); } elseif (isset($file)) { $data = array($file); } else { $data = array('<?php ... ?>'); } if ($o & 16) { if (empty($info['max_version'])) { $data[] = $info['version']; } else { $data[] = implode("\r\n", array($info['version'], $info['max_version'])); } } if ($o & 1) { $data[] = $info['cond_code'][0]; } if ($o & 2) { $data[] = $ext; } if ($o & 4) { if ($o & 8) { $data[] = $const; } else { $data[] = implode("\r\n", $info['constants']); } } else { if ($o & 8) { $data[] = implode("\r\n", $info['tokens']); } } $table->addRow($data); unset($info['max_version']); unset($info['version']); unset($info['classes']); unset($info['functions']); unset($info['extensions']); unset($info['constants']); unset($info['tokens']); unset($info['cond_code']); $ignored = $info['ignored_files']; $all_functions = array(); unset($info['ignored_files']); unset($info['ignored_functions']); unset($info['ignored_extensions']); unset($info['ignored_constants']); // summarize : print only summary for directory without files details if ($this->args['summarize'] === false && isset($dir)) { foreach ($info as $file => $info) { if (is_numeric($file[0])) { // extra information available only when debug mode is on $all_functions[$file] = $info; continue; } if ($info === false) { continue; // skip this (invalid) file } $ext = implode("\r\n", $info['extensions']); $const = implode("\r\n", array_merge($info['constants'], $info['tokens'])); $file = str_replace(array('\\', '/'), $ds, $file); $table->addSeparator(); $data = array($file); if ($o & 16) { if (empty($info['max_version'])) { $data[] = $info['version']; } else { $data[] = implode("\r\n", array($info['version'], $info['max_version'])); } } if ($o & 1) { $data[] = $info['cond_code'][0]; } if ($o & 2) { $data[] = $ext; } if ($o & 4) { if ($o & 8) { $data[] = $const; } else { $data[] = implode("\r\n", $info['constants']); } } else { if ($o & 8) { $data[] = implode("\r\n", $info['tokens']); } } $table->addRow($data); } } else { foreach ($info as $file => $info) { if (is_numeric($file[0])) { // extra information available only when debug mode is on $all_functions[$file] = $info; } } } $output = $table->getTable(); // verbose level $v = isset($this->args['verbose']) ? $this->args['verbose'] : 0; // command line resume if ($v & 1) { $output .= "\nCommand Line resume :\n\n"; $table = new Console_Table(); $table->setHeaders(array('Option', 'Value')); $filter0 = array(&$this, '_splitOption'); $table->addFilter(0, $filter0); $filter1 = array(&$this, '_splitValue'); $table->addFilter(1, $filter1); if (is_array($this->args)) { foreach ($this->args as $key => $raw) { if ($key == 'summarize') { $raw = $raw === true ? 'TRUE' : 'FALSE'; } if (is_array($raw)) { $raw = implode(', ', $raw); } $contents = array($key, $raw); $table->addRow($contents); } } $output .= $table->getTable(); } // parser options resume if ($v & 2) { $output .= "\nParser options :\n\n"; $table = new Console_Table(); $table->setHeaders(array('Option', 'Value')); $filter0 = array(&$this, '_splitOption'); $table->addFilter(0, $filter0); $filter1 = array(&$this, '_splitValue'); $table->addFilter(1, $filter1); $opts = $this->_parser->options; if (is_array($opts)) { foreach ($opts as $key => $raw) { if ($key == 'debug' || $key == 'recurse_dir' || $key == 'is_string') { $raw = $raw === true ? 'TRUE' : 'FALSE'; } if (substr($key, -6) == '_match') { $val = array_values($raw[1]); array_unshift($val, $raw[0]); $raw = implode("\r\n", $val); } else { if (is_array($raw)) { $raw = implode("\r\n", $raw); } } $contents = array($key, $raw); $table->addRow($contents); } } $output .= $table->getTable(); } // extra information if ($v & 4) { $output .= "\nDebug:\n\n"; $table = new Console_Table(); $table->setHeaders(array('Version', 'Function', 'Extension', 'PECL')); foreach ($all_functions as $version => $functions) { foreach ($functions as $func) { $table->addRow(array($version, $func['function'], $func['extension'], isset($func['pecl']) ? $func['pecl'] === true ? 'yes' : 'no' : '')); } } $output .= $table->getTable(); } echo $output; }
/** * Parse File Input * * @return void * @access private * @since 0.8.0 */ function _parseFile() { $info = $this->parseFile($this->file, $this->options); if ($info === false) { $err = 'Failed opening file "' . $this->file . '". Please check your spelling and try again.'; $this->_printUsage($err); return; } $table = new Console_Table(); $table->setHeaders(array('File', 'Version', 'Extensions', 'Constants/Tokens')); $filter = array(&$this, '_splitFilename'); $table->addFilter(0, $filter); $ext = implode("\r\n", $info['extensions']); $const = implode("\r\n", $info['constants']); $table->addRow(array($this->file, $info['version'], $ext, $const)); $output = $table->getTable(); // verbose level $v = $this->args->getValue('v'); // command line resume if ($v & 1) { $output .= "\nCommand Line resume :\n\n"; $table = new Console_Table(); $table->setHeaders(array('Option', 'Value')); $opts = $this->args->getValues(); if (is_array($opts)) { foreach ($opts as $key => $raw) { if (is_array($raw)) { $raw = implode(', ', $raw); } $contents = array($key, $raw); $table->addRow($contents); } } $output .= $table->getTable(); } // parser options resume if ($v & 2) { $output .= "\nParser options :\n\n"; $table = new Console_Table(); $table->setHeaders(array('Option', 'Value')); $opts = $this->options; if (is_array($opts)) { foreach ($opts as $key => $raw) { if ($key == 'debug' || $key == 'recurse_dir') { $raw = $raw === true ? 'TRUE' : 'FALSE'; } if (is_array($raw)) { $raw = implode("\r\n", $raw); } $contents = array($key, $raw); $table->addRow($contents); } } $output .= $table->getTable(); } // extra information if ($v & 4) { $output .= "\nDebug:\n\n"; $table = new Console_Table(); $table->setHeaders(array('Version', 'Function', 'Extension')); unset($info['max_version']); unset($info['version']); unset($info['constants']); unset($info['extensions']); foreach ($info as $version => $functions) { foreach ($functions as $func) { $table->addRow(array($version, $func['function'], $func['extension'])); } } $output .= $table->getTable(); } echo $output; }
/** * Return Console_Table object * * Used for displaying detail lines of the report in tabular format. * * @return Console_Table */ public function table() { $tbl = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, " ", 0); //set up filters for limiting widths of columns inside the table $filter0 = array($this, '_splitName'); $tbl->addFilter(0, $filter0); $filter1 = array($this, '_splitSize'); $tbl->addFilter(1, $filter1); if ($this->cols == 3) { $filter2 = array($this, '_splitDetail'); $tbl->addFilter(2, $filter2); } return $tbl; }
/** * Retrieve/format statistics. * * @since 15xxxx Initial release. */ protected function statistics() { $args = ['type' => $this->type, 'days' => $this->days, 'weeks' => $this->weeks, 'months' => $this->months, 'years' => $this->years, 'start_time' => $this->start_time, 'source' => $this->source, 'sku' => $this->sku, 'key' => $this->config->websharks->api_key]; $endpoint = 'https://www.websharks-inc.com/sales/api.php'; $endpoint = $this->UrlQuery->addArgs($args, $endpoint); $response = json_decode($this->UrlRemote->request('GET::' . $endpoint)); if (!is_object($response) || !empty($response->error)) { if (!empty($response->error)) { throw new \Exception('Unable to retrieve statistics.' . "\n" . 'The API said: `' . $response->error . '`'); } throw new \Exception('Unable to retrieve statistics.' . "\n" . 'The API call failed w/ an unknown error.'); } $statistics = ''; // Initialize. $table = new \Console_Table(CONSOLE_TABLE_ALIGN_LEFT, CONSOLE_TABLE_BORDER_ASCII, 1, 'UTF-8', true); $table_color = new \Console_Color2(); // Coloration class. $table_colorize_amount = function ($amount) use($table_color) { return $table_color->convert('%G' . $amount . '%n'); }; $table_colorize_from = function ($from) use($table_color) { return $table_color->convert('%b' . $from . '%n'); }; $table_colorize_to = function ($to) use($table_color) { return $table_color->convert('%b' . $to . '%n'); }; $table->setHeaders(['From', 'To', 'Amount']); $table->addFilter(0, $table_colorize_from); $table->addFilter(1, $table_colorize_to); $table->addFilter(2, $table_colorize_amount); $chart = ''; // Initialize. $chart_data = ''; // Initialize. $chart_gnuplot = []; // Initialize. $chart_first_from = $chart_last_to = ''; // Initialize. $chart_data_file = $this->FsDir->tmp() . '/' . md5(__CLASS__ . 'gnuplot') . '.dat'; date_default_timezone_set('UTC'); // UTC timezone. $statistics .= '**' . $response->title . '**'; if ($response->caption) { // Caption also? $statistics .= ' _*' . $response->caption . '*_'; } $statistics .= "\n"; // Additional line break. foreach ($response->results as $_result) { $_from = date('D M d, Y @ H:i a T', strtotime($_result->from)); $_to = date('D M d, Y @ H:i a T', strtotime($_result->to)); $table->addRow([$_from, $_to, '$' . $_result->amount]); } unset($_result); // Housekeeping. $statistics .= $table->getTable(); // Append table. foreach ($response->results as $_result) { if (empty($chart_first_from)) { $chart_first_from = date('D M d, Y @ H:i a T', strtotime($_result->from)); } $chart_last_to = date('D M d, Y @ H:i a T', strtotime($_result->to)); $chart_data .= '"" ' . $_result->amount . "\n"; } $chart_data = trim($chart_data); file_put_contents($chart_data_file, $chart_data); unset($_result); // Housekeeping. $chart_gnuplot[] = 'gnuplot'; $chart_gnuplot[] = '-e'; // Eval the following. $chart_gnuplot[] = 'set terminal dumb size 83, 20;' . ' set yrange [0:*]; set ylabel "Gross Revenue (in USD)";' . ' set xlabel "' . $chart_first_from . ' - ' . $chart_last_to . '";' . ' plot "' . str_replace('"', '', $chart_data_file) . '" using 2:xtic(1) notitle with histograms'; exec(implode(' ', array_map('escapeshellarg', $chart_gnuplot)), $chart, $chart_status); if ($chart_status === 0) { $statistics .= implode("\n", $chart); // Append chart. } return $statistics; }