TableStyle.php 5.1 KB

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