TableStyle.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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\Exception\InvalidArgumentException;
  12. use Symfony\Component\Console\Exception\LogicException;
  13. /**
  14. * Defines the styles for a Table.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. * @author Саша Стаменковић <umpirsky@gmail.com>
  18. */
  19. class TableStyle
  20. {
  21. private $paddingChar = ' ';
  22. private $horizontalBorderChar = '-';
  23. private $verticalBorderChar = '|';
  24. private $crossingChar = '+';
  25. private $cellHeaderFormat = '<info>%s</info>';
  26. private $cellRowFormat = '%s';
  27. private $cellRowContentFormat = ' %s ';
  28. private $borderFormat = '%s';
  29. private $padType = STR_PAD_RIGHT;
  30. /**
  31. * Sets padding character, used for cell padding.
  32. *
  33. * @param string $paddingChar
  34. *
  35. * @return $this
  36. */
  37. public function setPaddingChar($paddingChar)
  38. {
  39. if (!$paddingChar) {
  40. throw new LogicException('The padding char must not be empty');
  41. }
  42. $this->paddingChar = $paddingChar;
  43. return $this;
  44. }
  45. /**
  46. * Gets padding character, used for cell padding.
  47. *
  48. * @return string
  49. */
  50. public function getPaddingChar()
  51. {
  52. return $this->paddingChar;
  53. }
  54. /**
  55. * Sets horizontal border character.
  56. *
  57. * @param string $horizontalBorderChar
  58. *
  59. * @return $this
  60. */
  61. public function setHorizontalBorderChar($horizontalBorderChar)
  62. {
  63. $this->horizontalBorderChar = $horizontalBorderChar;
  64. return $this;
  65. }
  66. /**
  67. * Gets horizontal border character.
  68. *
  69. * @return string
  70. */
  71. public function getHorizontalBorderChar()
  72. {
  73. return $this->horizontalBorderChar;
  74. }
  75. /**
  76. * Sets vertical border character.
  77. *
  78. * @param string $verticalBorderChar
  79. *
  80. * @return $this
  81. */
  82. public function setVerticalBorderChar($verticalBorderChar)
  83. {
  84. $this->verticalBorderChar = $verticalBorderChar;
  85. return $this;
  86. }
  87. /**
  88. * Gets vertical border character.
  89. *
  90. * @return string
  91. */
  92. public function getVerticalBorderChar()
  93. {
  94. return $this->verticalBorderChar;
  95. }
  96. /**
  97. * Sets crossing character.
  98. *
  99. * @param string $crossingChar
  100. *
  101. * @return $this
  102. */
  103. public function setCrossingChar($crossingChar)
  104. {
  105. $this->crossingChar = $crossingChar;
  106. return $this;
  107. }
  108. /**
  109. * Gets crossing character.
  110. *
  111. * @return string $crossingChar
  112. */
  113. public function getCrossingChar()
  114. {
  115. return $this->crossingChar;
  116. }
  117. /**
  118. * Sets header cell format.
  119. *
  120. * @param string $cellHeaderFormat
  121. *
  122. * @return $this
  123. */
  124. public function setCellHeaderFormat($cellHeaderFormat)
  125. {
  126. $this->cellHeaderFormat = $cellHeaderFormat;
  127. return $this;
  128. }
  129. /**
  130. * Gets header cell format.
  131. *
  132. * @return string
  133. */
  134. public function getCellHeaderFormat()
  135. {
  136. return $this->cellHeaderFormat;
  137. }
  138. /**
  139. * Sets row cell format.
  140. *
  141. * @param string $cellRowFormat
  142. *
  143. * @return $this
  144. */
  145. public function setCellRowFormat($cellRowFormat)
  146. {
  147. $this->cellRowFormat = $cellRowFormat;
  148. return $this;
  149. }
  150. /**
  151. * Gets row cell format.
  152. *
  153. * @return string
  154. */
  155. public function getCellRowFormat()
  156. {
  157. return $this->cellRowFormat;
  158. }
  159. /**
  160. * Sets row cell content format.
  161. *
  162. * @param string $cellRowContentFormat
  163. *
  164. * @return $this
  165. */
  166. public function setCellRowContentFormat($cellRowContentFormat)
  167. {
  168. $this->cellRowContentFormat = $cellRowContentFormat;
  169. return $this;
  170. }
  171. /**
  172. * Gets row cell content format.
  173. *
  174. * @return string
  175. */
  176. public function getCellRowContentFormat()
  177. {
  178. return $this->cellRowContentFormat;
  179. }
  180. /**
  181. * Sets table border format.
  182. *
  183. * @param string $borderFormat
  184. *
  185. * @return $this
  186. */
  187. public function setBorderFormat($borderFormat)
  188. {
  189. $this->borderFormat = $borderFormat;
  190. return $this;
  191. }
  192. /**
  193. * Gets table border format.
  194. *
  195. * @return string
  196. */
  197. public function getBorderFormat()
  198. {
  199. return $this->borderFormat;
  200. }
  201. /**
  202. * Sets cell padding type.
  203. *
  204. * @param int $padType STR_PAD_*
  205. *
  206. * @return $this
  207. */
  208. public function setPadType($padType)
  209. {
  210. if (!\in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
  211. throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
  212. }
  213. $this->padType = $padType;
  214. return $this;
  215. }
  216. /**
  217. * Gets cell padding type.
  218. *
  219. * @return int
  220. */
  221. public function getPadType()
  222. {
  223. return $this->padType;
  224. }
  225. }