Drupal investigation

TableHelper.php 6.0KB

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