/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $options['unlimited'] = true; $options['list_for'] = 'admin'; $SitesDb = new \System\Core\Models\SitesDb($this->Db); $site_list = $SitesDb->listSites($options); unset($SitesDb, $options); if (is_array($site_list) && array_key_exists('total', $site_list) && $site_list['total'] > '0' && array_key_exists('items', $site_list)) { $output->writeln('There are total ' . $site_list['total'] . ' sites in db.'); $output->writeln('------------------------------'); $Table = new \Symfony\Component\Console\Helper\Table($output); $list_site_rows = []; foreach ($site_list['items'] as $row) { if ($row->site_status == '2') { $site_status = 'Maintenance'; } elseif ($row->site_status == '1') { $site_status = 'Enabled'; } else { $site_status = 'Disabled'; } $list_site_rows[] = [$row->site_id, $row->site_name, $row->site_domain, $site_status]; unset($site_status); } // endforeach; $Table->setHeaders(['Site ID', 'Site name', 'Domain', 'Status'])->setRows($list_site_rows); $Table->render(); unset($list_site_rows, $row, $Table); } else { $output->writeln('<error>Unable to list site or there is no site.</error>'); } unset($site_list); }
/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $options['unlimited'] = true; $RoutesDb = new \System\Core\Models\RoutesDb($this->Db); $site_list = $RoutesDb->listRoutes($options); unset($RoutesDb, $options); if (is_array($site_list) && array_key_exists('total', $site_list) && $site_list['total'] > '0' && array_key_exists('items', $site_list)) { $output->writeln('There are total ' . $site_list['total'] . ' routes in db.'); $output->writeln('------------------------------'); $Table = new \Symfony\Component\Console\Helper\Table($output); $list_route_rows = []; foreach ($site_list['items'] as $row) { if ($row->route_core == '1') { $route_core = 'Yes'; } else { $route_core = 'No'; } $list_route_rows[] = [$row->route_id, $row->route_method . (strtolower($row->route_method) == 'match' ? "\n" . '(' . $row->route_match_method . ')' : ''), $row->route_uri, $row->route_controller, $row->route_bind, $route_core]; unset($route_core); } // endforeach; $Table->setHeaders(['Route ID', 'Method', 'URI', 'Controller', 'Name', 'Is core'])->setRows($list_route_rows); $Table->render(); unset($list_route_rows, $row, $Table); } else { $output->writeln('<error>Unable to list route or there is no route.</error>'); } unset($site_list); }
/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $options['unlimited'] = true; $options['list_for'] = 'admin'; $ModulesDb = new \System\Core\Models\ModulesDb($this->Db); $module_list = $ModulesDb->listModulesQb($options); unset($ModulesDb, $options); if (is_array($module_list) && array_key_exists('total', $module_list) && $module_list['total'] > '0' && array_key_exists('items', $module_list)) { $output->writeln('There are total ' . $module_list['total'] . ' modules in db.'); $output->writeln('------------------------------'); foreach ($module_list['items'] as $row) { $output->write('ID: "' . $row->module_id . '"'); $output->write(' Module: "' . $row->module_system_name . '"'); $output->writeln(' Version: "' . $row->module_version . '"'); // module in each sites. if (property_exists($row, 'module_sites')) { $Table = new \Symfony\Component\Console\Helper\Table($output); $Table->setHeaders(['Site ID', 'Enabled']); foreach ($row->module_sites as $msrow) { $Table->addRows([[$msrow->site_id, $msrow->module_enable == '1' ? 'Yes' : 'No']]); } // endforeach; unset($msrow); $Table->render(); unset($Table); $output->writeln('------------------------------'); } } // endforeach; unset($row); } else { $output->writeln('<error>Unable to list module or there is no module.</error>'); } unset($module_list); }
protected function execute(InputInterface $input, OutputInterface $output) { $tags = $input->getOption('tag'); $tags = $this->convertTags($tags); $mapping = ['InstanceId' => 'InstanceId', 'ImageId' => 'ImageId', 'State' => 'State.Name', 'SubnetId' => 'SubnetId', 'AZ' => 'Placement.AvailabilityZone', 'PublicIp' => 'PublicIpAddress', 'PrivateIp' => 'PrivateIpAddress', 'KeyName' => 'KeyName']; // dynamically add current tags foreach (array_keys($tags) as $tagName) { $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]'; } foreach ($input->getOption('column') as $tagName) { $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]'; } $repository = new Repository(); $instanceCollection = $repository->findEc2InstancesByTags($tags); $rows = []; foreach ($instanceCollection as $instance) { /* @var $instance Instance */ $rows[] = $instance->extractData($mapping); } if (count($rows)) { $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array_keys(end($rows)))->setRows($rows); $table->render(); } else { $output->writeln('No matching instances found.'); } }
/** * Execute the console command. * * @return void */ public function fire() { // Fire event before the Cron jobs will be executed \Event::fire('cron.collectJobs'); $report = Cron::run(); if ($report['inTime'] === -1) { $inTime = -1; } else { if ($report['inTime']) { $inTime = 'true'; } else { $inTime = 'false'; } } // Get Laravel version $laravel = app(); $version = $laravel::VERSION; if ($version < '5.2') { // Create table for old Laravel versions. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs')); $table->addRow(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons']))); } else { // Create table for new Laravel versions. $table = new \Symfony\Component\Console\Helper\Table($this->getOutput()); $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs'))->setRows(array(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons'])))); } // Output table. $table->render($this->getOutput()); }
protected function execute(InputInterface $input, OutputInterface $output) { $profileManager = new \AwsInspector\ProfileManager(); $rows = []; foreach ($profileManager->listAllProfiles() as $profileName) { $rows[] = [$profileName]; } $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array('Profile Name'))->setRows($rows); $table->render(); }
/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $options['unlimited'] = true; $options['list_for'] = 'admin'; $ThemesDb = new \System\Core\Models\ThemesDb($this->Db); $theme_list = $ThemesDb->listThemes($options); unset($ThemesDb, $options); if (is_array($theme_list) && array_key_exists('total', $theme_list) && $theme_list['total'] > '0' && array_key_exists('items', $theme_list)) { $output->writeln('There are total ' . $theme_list['total'] . ' themes in db.'); $output->writeln('------------------------------'); foreach ($theme_list['items'] as $row) { $output->write('ID: "' . $row->theme_id . '"'); $output->write(' Theme: "' . $row->theme_system_name . '"'); $output->writeln(' Version: "' . $row->theme_version . '"'); // module in each sites. if (property_exists($row, 'theme_sites')) { $Table = new \Symfony\Component\Console\Helper\Table($output); $Table->setHeaders(['Site ID', 'Enabled', 'Default front', 'Default admin', 'Settings']); foreach ($row->theme_sites as $tsrow) { if ($tsrow->theme_enable == '1') { $theme_enable = 'Yes'; } else { $theme_enable = 'No'; } if ($tsrow->theme_default == '1') { $theme_default = 'Yes'; } else { $theme_default = 'No'; } if ($tsrow->theme_default_admin == '1') { $theme_default_admin = 'Yes'; } else { $theme_default_admin = 'No'; } $Table->addRows([[$tsrow->site_id, $theme_enable, $theme_default, $theme_default_admin, $tsrow->theme_settings]]); unset($theme_default, $theme_default_admin, $theme_enable); } // endforeach; unset($tsrow); $Table->render(); unset($Table); $output->writeln('------------------------------'); } } // endforeach; unset($row); } else { $output->writeln('<error>Unable to list theme or there is no theme.</error>'); } unset($theme_list); }
/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); // $output->write(str_pad("\x0D", 80, "\x20")); // $output->writeln(''); // overview $total = $this->bound->calculate($collection); $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time')))); $output->writeln('<info>Average for each module:</info>'); $output->writeln(''); $hasOOP = null !== $total->getSum('instability'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array_merge(array('Name', 'Complexity', 'Myer Distance', 'Maintainability', 'LLOC', 'Comment weight', 'Vocabulary', 'Volume', 'Bugs', 'Difficulty'), $hasOOP ? array('lcom', 'SysComplexity', 'Instability', 'Abstractness', 'ce', 'ca') : array())); foreach ($groupedResults as $result) { $table->addRow(array_merge(array(str_repeat(' ', $result->getDepth()) . $result->getName(), $this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array())); } $table->render(); return $output->fetch(); }
function run() { $this->dmx = new \DmxHttp\Controller\DMXPost(); $this->dmx->addDevice(new Spot(6)); $this->dmx->addDevice(new Spot(12)); $this->dmx->addDevice(new Spot(18)); $this->dmx->addDevice(new Spot(24)); $this->dmx->addDevice(new Spot(30)); $this->dmx->addDevice(new Spot(36)); $this->dmx->addDevice(new Spot(42)); $this->dmx->addDevice(new Spot(48)); $this->dmx->addDevice(new Scanner(300)); $this->dmx->addDevice(new Scanner(305)); $this->dmx->addDevice(new Scanner(310)); $this->dmx->addDevice(new Scanner(314)); $console = new \Symfony\Component\Console\Application(); $console->register("ls")->setDefinition(array())->setDescription("list devices")->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array('Start Channel', 'Type', 'status')); foreach ($this->dmx->getDevices() as $device) { $table->addRow([$device->getStartChannel(), get_class($device), '[' . implode(',', $device->getChannels()) . ']']); } $table->render(); }); $console->register("run")->setDefinition(array(new InputArgument('device', InputArgument::REQUIRED, 'start channel of a device'), new InputArgument('method', InputArgument::REQUIRED, 'method'), new InputArgument('args', InputArgument::IS_ARRAY, 'arguments')))->setDescription("set command")->setCode(function (InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $device = null; foreach ($this->dmx->getDevices() as $_device) { if ($_device->getStartChannel() == $input->getArgument("device")) { $device = $_device; break; } } if ($device === null) { $output->writeln("<error>can't find device</error>"); return 1; } $method = $input->getArgument("method"); $args = $input->getArgument("args"); call_user_func_array([$device, $method], $args); $this->dmx->send(); }); $console->run(); }
/** * Execute the console command. * * @return void */ public function fire() { // Get the current timestamp and fire the collect event $runDate = new \DateTime(); \Event::fire('cron.collectJobs', array($runDate->getTimestamp())); // Get all registered Cron jobs $jobs = Cron::getCronJobs(); // Get Laravel version $laravel = app(); $version = $laravel::VERSION; if ($version < '5.2') { // Create the table helper with headers. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Jobname', 'Expression', 'Activated')); // Run through all registered jobs for ($i = 0; $i < count($jobs); $i++) { // Get current job entry $job = $jobs[$i]; // If job is enabled or disable use the defined string instead of 1 or 0 $enabled = $job['enabled'] ? 'Enabled' : 'Disabled'; // Add this job to the table. $table->addRow(array($job['name'], $job['expression']->getExpression(), $enabled)); } } else { // Create table for new Laravel versions. $table = new \Symfony\Component\Console\Helper\Table($this->getOutput()); $table->setHeaders(array('Jobname', 'Expression', 'Activated')); $rows = []; // Run through all registered jobs for ($i = 0; $i < count($jobs); $i++) { // Get current job entry $job = $jobs[$i]; // If job is enabled or disable use the defined string instead of 1 or 0 $enabled = $job['enabled'] ? 'Enabled' : 'Disabled'; array_push($rows, array($job['name'], $job['expression']->getExpression(), $enabled)); } $table->setRows($rows); } // Render and output the table. $table->render($this->getOutput()); }
protected function execute(InputInterface $input, OutputInterface $output) { $query = $input->getArgument('query'); $fields = explode(',', $input->getOption('output')); $service = $this->getContainer()->get('cards_data'); $conditions = $service->syntax($query); $conditions = $service->validateConditions($conditions); $q = $service->buildQueryFromConditions($conditions); $result = []; $rows = $service->get_search_rows($conditions, 'set'); foreach ($rows as $card) { $cardinfo = $service->getCardInfo($card, false); $filtered = array_filter($cardinfo, function ($key) use($fields) { return in_array($key, $fields); }, ARRAY_FILTER_USE_KEY); $result[] = $filtered; } $table = new \Symfony\Component\Console\Helper\Table($output); $table->setRows($result); $table->render(); $output->writeln(''); $output->writeln(count($rows) . " cards"); }
if (!isset($result[$span['a']['title']])) { $result[$span['a']['title']] = [$span['a']['title'], max($span['e']) - min($span['b']), count($span['b'])]; } else { $result[$span['a']['title']][1] += max($span['e']) - min($span['b']); $result[$span['a']['title']][2] += count($span['b']); } } return $result; }; $console->register('analyze')->setDefinition(array())->setDescription('Displays the files in the given directory')->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) use($flatten_spans) { $file = __DIR__ . '/../local/trace_17186.json'; $file = __DIR__ . '/../local/trace_17717.json'; $trace = json_decode(file_get_contents($file), true); $appInfo = array_shift($trace['spans']); $output->writeln('App run info:'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setRows(array(array('id', $trace['id']), array('TransactionName', $trace['tx']), array('PHP Version:', $appInfo['a']['php']), array('title:', $appInfo['a']['title']))); $table->render(); $output->writeln('App Summary:'); $table = new \Symfony\Component\Console\Helper\Table($output); $tableStyleRightAligned = new \Symfony\Component\Console\Helper\TableStyle(); $tableStyleRightAligned->setPadType(STR_PAD_LEFT); $table->setColumnStyle(1, $tableStyleRightAligned); $table->setRows(array(array('compile count:', $appInfo['a']['cct'] ?? ''), array('compile Wall Time:', $appInfo['a']['cwt'] ?? ''), array('compile CPU Time:', $appInfo['a']['cpu']), array('Garbage Collection Runs:', $appInfo['a']['gc'] ?? ''), array('Garbage Collected:', $appInfo['a']['gcc'] ?? ''))); $table->render(); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array('title', 'time', 'call count'))->setRows($flatten_spans($trace['spans'])); $table->render(); $output->writeln('End of command'); }); $console->run();
} } if ($doSkip) { continue; } if ((int) $metrics['elements'] == 0) { continue; } $covered = round((int) $metrics['coveredelements'] / (int) $metrics['elements'] * 100, 2); if ($covered < $minCoveragePercentage) { $failedCoverageChecks[] = ['Class' => $class, 'Coverage' => $covered]; } } if (!empty($failedCoverageChecks)) { $out->writeln('<error>Following classes found to be failing coverage check</error>'); $table = new \Symfony\Component\Console\Helper\Table($out); $table->setHeaders(['Class', 'Coverage']); $table->addRows($failedCoverageChecks); $table->render(); exit(0); //will be switched to 1 when coverage is decent } else { $out->writeln('<info>Coverage Checks: OK</info>'); exit(0); } /*** helper functions **/ function help() { global $out; $helpText = <<<HELP Usage: check-coverage.php <clover-file> <min-percentage>
/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); // $output->write(str_pad("\x0D", 80, "\x20")); // $output->writeln(''); // overview $total = $this->bound->calculate($collection); $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time')))); $output->writeln('<info>Average for each module:</info>'); $output->writeln(''); $hasOOP = null !== $total->getSum('instability'); $output->writeln('1 - Complexity'); $output->writeln('2 - Myer Distance: derivated from Cyclomatic complexity'); $output->writeln('3 - Maintainability'); $output->writeln('4 - LLOC: Number of logical lines of code'); $output->writeln('5 - Comment weight: measure the ratio between logical code and comments'); $output->writeln('6 - Vocabulary used in code'); $output->writeln('7 - Volume'); $output->writeln('8 - Bugs: Number of estimated bugs by file'); $output->writeln('9 - Difficulty of the code'); $output->writeln('A - LCOM: Lack of cohesion of methods measures the cohesiveness of a class'); $output->writeln('B - System complexity'); $output->writeln('C - Instability: Indicates the class is resilience to change'); $output->writeln('D - Abstractness: Number of abstract classes'); $output->writeln('E - Efferent coupling (CE): Number of classes that the class depend'); $output->writeln('F - Afferent coupling (CA): Number of classes affected by this class'); $output->writeln(''); $output->writeln('More details about metrics: http://www.phpmetrics.org/documentation/index.html'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array_merge(array('1', '2', '3', '4', '5', '6', '7', '8', '9'), $hasOOP ? array('A', 'B', 'C', 'D', 'E', 'F') : array())); foreach ($groupedResults as $key => $result) { if ($result->getDepth() > 1) { $table->addRow(new TableSeparator()); } $table->addRow(array(new TableCell($result->getName(), array('colspan' => 15)))); $table->addRow(new TableSeparator()); $table->addRow(array_merge(array($this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array())); } $table->render(); return $output->fetch(); }
{ $post = new \Kcs\Serializer\Tests\Fixtures\BlogPost('FooooooooooooooooooooooBAR', new \Kcs\Serializer\Tests\Fixtures\Author('Foo'), new \DateTime(), new \Kcs\Serializer\Tests\Fixtures\Publisher('Bar')); for ($i = 0; $i < 10; ++$i) { $post->addComment(new \Kcs\Serializer\Tests\Fixtures\Comment(new \Kcs\Serializer\Tests\Fixtures\Author('foo'), 'foobar')); } return $post; } $serializer = \Kcs\Serializer\SerializerBuilder::create()->setEventDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher())->build(); $collection = createCollection(); $metrics = []; $f = function ($format) use($serializer, $collection) { $serializer->serialize($collection, $format); }; // Load all necessary classes into memory. $f('array'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(['Format', 'Direction', 'Time']); $progressBar = new \Symfony\Component\Console\Helper\ProgressBar($output, 8); $progressBar->start(); foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'serialize', benchmark($f, $format)]); $progressBar->advance(); } $serialized = ['array' => $serializer->serialize($collection, 'array'), 'json' => $serializer->serialize($collection, 'json'), 'yml' => $serializer->serialize($collection, 'yml'), 'xml' => $serializer->serialize($collection, 'xml')]; $type = new \Kcs\Serializer\Type\Type('array', [\Kcs\Serializer\Type\Type::from(\Kcs\Serializer\Tests\Fixtures\BlogPost::class)]); $d = function ($format) use($serializer, $serialized, $type) { $serializer->deserialize($serialized[$format], $type, $format); }; foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'deserialize', benchmark($d, $format)]); $progressBar->advance();