Esempio n. 1
0
 public function table(TableHelper $table)
 {
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->setCellHeaderFormat('<info>%s</info>');
     $table->setCellRowFormat('%s');
     $table->render($this);
 }
Esempio n. 2
0
 /** {@inheritdoc} */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $srcHost = $input->getArgument(self::ATTR_HOST);
     $srcPort = $input->getOption(self::OPT_PORT);
     $sort = $input->getOption(self::OPT_SORT);
     $order = $input->getOption(self::OPT_ORDER);
     $noZeros = $input->getOption(self::OPT_NO_ZEROS);
     $columns = ['name' => 'name', 'current-jobs-ready' => 'ready', 'current-jobs-reserved' => 'reserved', 'current-jobs-delayed' => 'delayed', 'current-jobs-buried' => 'buried'];
     $src = new Pheanstalk($srcHost, $srcPort);
     $table = new TableHelper(false);
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->setHeaders($columns);
     $tubeNames = $src->listTubes();
     ksort($tubeNames);
     $data = [];
     foreach ($tubeNames as $tube) {
         /** @var ArrayResponse $response */
         $response = $src->statsTube($tube);
         $tubeData = $response->getArrayCopy();
         $tubeData = array_intersect_key($tubeData, $columns);
         if ($noZeros) {
             foreach ($tubeData as $key => $value) {
                 if ('0' === $value) {
                     $tubeData[$key] = '';
                 }
             }
         }
         $data[] = $tubeData;
     }
     $column = array_search($sort, $columns);
     uasort($data, function (array $a1, array $a2) use($column, $order) {
         return strnatcmp($a1[$column], $a2[$column]) * $order;
     });
     $table->addRows($data);
     $table->render($output);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
 {
     $showPrivate = isset($options['show_private']) && $options['show_private'];
     $showTag = isset($options['tag']) ? $options['tag'] : null;
     if ($showPrivate) {
         $label = '<comment>Public</comment> and <comment>private</comment> services';
     } else {
         $label = '<comment>Public</comment> services';
     }
     if ($showTag) {
         $label .= ' with tag <info>' . $options['tag'] . '</info>';
     }
     $this->writeText($this->formatSection('container', $label) . "\n", $options);
     $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
     $maxTags = array();
     foreach ($serviceIds as $key => $serviceId) {
         $definition = $this->resolveServiceDefinition($builder, $serviceId);
         if ($definition instanceof Definition) {
             // filter out private services unless shown explicitly
             if (!$showPrivate && !$definition->isPublic()) {
                 unset($serviceIds[$key]);
                 continue;
             }
             if ($showTag) {
                 $tags = $definition->getTag($showTag);
                 foreach ($tags as $tag) {
                     foreach ($tag as $key => $value) {
                         if (!isset($maxTags[$key])) {
                             $maxTags[$key] = strlen($key);
                         }
                         if (strlen($value) > $maxTags[$key]) {
                             $maxTags[$key] = strlen($value);
                         }
                     }
                 }
             }
         }
     }
     $tagsCount = count($maxTags);
     $tagsNames = array_keys($maxTags);
     $table = new TableHelper();
     $table->setLayout(TableHelper::LAYOUT_COMPACT);
     $table->setHeaders(array_merge(array('Service ID'), $tagsNames, array('Class name')));
     foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
         $definition = $this->resolveServiceDefinition($builder, $serviceId);
         if ($definition instanceof Definition) {
             if ($showTag) {
                 foreach ($definition->getTag($showTag) as $key => $tag) {
                     $tagValues = array();
                     foreach ($tagsNames as $tagName) {
                         $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : "";
                     }
                     if (0 === $key) {
                         $table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass())));
                     } else {
                         $table->addRow(array_merge(array('  "'), $tagValues, array('')));
                     }
                 }
             } else {
                 $table->addRow(array($serviceId, $definition->getClass()));
             }
         } elseif ($definition instanceof Alias) {
             $alias = $definition;
             $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
         } else {
             // we have no information (happens with "service_container")
             $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
         }
     }
     $this->renderTable($table);
 }