[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/console/Helper/ -> TableHelper.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Console\Helper;
  13  
  14  use Symfony\Component\Console\Exception\InvalidArgumentException;
  15  use Symfony\Component\Console\Output\NullOutput;
  16  use Symfony\Component\Console\Output\OutputInterface;
  17  
  18  /**
  19   * Provides helpers to display table output.
  20   *
  21   * @author Саша Стаменковић <umpirsky@gmail.com>
  22   * @author Fabien Potencier <fabien@symfony.com>
  23   *
  24   * @deprecated since version 2.5, to be removed in 3.0
  25   *             Use {@link Table} instead.
  26   */
  27  class TableHelper extends Helper
  28  {
  29      const LAYOUT_DEFAULT = 0;
  30      const LAYOUT_BORDERLESS = 1;
  31      const LAYOUT_COMPACT = 2;
  32  
  33      private $table;
  34  
  35      public function __construct($triggerDeprecationError = true)
  36      {
  37          if ($triggerDeprecationError) {
  38              @trigger_error('The '.__CLASS__.' class is deprecated since Symfony 2.5 and will be removed in 3.0. Use the Symfony\Component\Console\Helper\Table class instead.', E_USER_DEPRECATED);
  39          }
  40  
  41          $this->table = new Table(new NullOutput());
  42      }
  43  
  44      /**
  45       * Sets table layout type.
  46       *
  47       * @param int $layout self::LAYOUT_*
  48       *
  49       * @return $this
  50       *
  51       * @throws InvalidArgumentException when the table layout is not known
  52       */
  53      public function setLayout($layout)
  54      {
  55          switch ($layout) {
  56              case self::LAYOUT_BORDERLESS:
  57                  $this->table->setStyle('borderless');
  58                  break;
  59  
  60              case self::LAYOUT_COMPACT:
  61                  $this->table->setStyle('compact');
  62                  break;
  63  
  64              case self::LAYOUT_DEFAULT:
  65                  $this->table->setStyle('default');
  66                  break;
  67  
  68              default:
  69                  throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
  70          }
  71  
  72          return $this;
  73      }
  74  
  75      public function setHeaders(array $headers)
  76      {
  77          $this->table->setHeaders($headers);
  78  
  79          return $this;
  80      }
  81  
  82      public function setRows(array $rows)
  83      {
  84          $this->table->setRows($rows);
  85  
  86          return $this;
  87      }
  88  
  89      public function addRows(array $rows)
  90      {
  91          $this->table->addRows($rows);
  92  
  93          return $this;
  94      }
  95  
  96      public function addRow(array $row)
  97      {
  98          $this->table->addRow($row);
  99  
 100          return $this;
 101      }
 102  
 103      public function setRow($column, array $row)
 104      {
 105          $this->table->setRow($column, $row);
 106  
 107          return $this;
 108      }
 109  
 110      /**
 111       * Sets padding character, used for cell padding.
 112       *
 113       * @param string $paddingChar
 114       *
 115       * @return $this
 116       */
 117      public function setPaddingChar($paddingChar)
 118      {
 119          $this->table->getStyle()->setPaddingChar($paddingChar);
 120  
 121          return $this;
 122      }
 123  
 124      /**
 125       * Sets horizontal border character.
 126       *
 127       * @param string $horizontalBorderChar
 128       *
 129       * @return $this
 130       */
 131      public function setHorizontalBorderChar($horizontalBorderChar)
 132      {
 133          $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
 134  
 135          return $this;
 136      }
 137  
 138      /**
 139       * Sets vertical border character.
 140       *
 141       * @param string $verticalBorderChar
 142       *
 143       * @return $this
 144       */
 145      public function setVerticalBorderChar($verticalBorderChar)
 146      {
 147          $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
 148  
 149          return $this;
 150      }
 151  
 152      /**
 153       * Sets crossing character.
 154       *
 155       * @param string $crossingChar
 156       *
 157       * @return $this
 158       */
 159      public function setCrossingChar($crossingChar)
 160      {
 161          $this->table->getStyle()->setCrossingChar($crossingChar);
 162  
 163          return $this;
 164      }
 165  
 166      /**
 167       * Sets header cell format.
 168       *
 169       * @param string $cellHeaderFormat
 170       *
 171       * @return $this
 172       */
 173      public function setCellHeaderFormat($cellHeaderFormat)
 174      {
 175          $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
 176  
 177          return $this;
 178      }
 179  
 180      /**
 181       * Sets row cell format.
 182       *
 183       * @param string $cellRowFormat
 184       *
 185       * @return $this
 186       */
 187      public function setCellRowFormat($cellRowFormat)
 188      {
 189          $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
 190  
 191          return $this;
 192      }
 193  
 194      /**
 195       * Sets row cell content format.
 196       *
 197       * @param string $cellRowContentFormat
 198       *
 199       * @return $this
 200       */
 201      public function setCellRowContentFormat($cellRowContentFormat)
 202      {
 203          $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
 204  
 205          return $this;
 206      }
 207  
 208      /**
 209       * Sets table border format.
 210       *
 211       * @param string $borderFormat
 212       *
 213       * @return $this
 214       */
 215      public function setBorderFormat($borderFormat)
 216      {
 217          $this->table->getStyle()->setBorderFormat($borderFormat);
 218  
 219          return $this;
 220      }
 221  
 222      /**
 223       * Sets cell padding type.
 224       *
 225       * @param int $padType STR_PAD_*
 226       *
 227       * @return $this
 228       */
 229      public function setPadType($padType)
 230      {
 231          $this->table->getStyle()->setPadType($padType);
 232  
 233          return $this;
 234      }
 235  
 236      /**
 237       * Renders table to output.
 238       *
 239       * Example:
 240       * +---------------+-----------------------+------------------+
 241       * | ISBN          | Title                 | Author           |
 242       * +---------------+-----------------------+------------------+
 243       * | 99921-58-10-7 | Divine Comedy         | Dante Alighieri  |
 244       * | 9971-5-0210-0 | A Tale of Two Cities  | Charles Dickens  |
 245       * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
 246       * +---------------+-----------------------+------------------+
 247       */
 248      public function render(OutputInterface $output)
 249      {
 250          $p = new \ReflectionProperty($this->table, 'output');
 251          $p->setAccessible(true);
 252          $p->setValue($this->table, $output);
 253  
 254          $this->table->render();
 255      }
 256  
 257      /**
 258       * {@inheritdoc}
 259       */
 260      public function getName()
 261      {
 262          return 'table';
 263      }
 264  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1