1515use cli \Shell ;
1616use cli \Streams ;
1717use cli \table \Ascii ;
18+ use cli \table \Column ;
1819use cli \table \Renderer ;
1920use cli \table \Tabular ;
2021
@@ -27,6 +28,7 @@ class Table {
2728 protected $ _footers = array ();
2829 protected $ _width = array ();
2930 protected $ _rows = array ();
31+ protected $ _alignments = array ();
3032
3133 /**
3234 * Initializes the `Table` class.
@@ -44,7 +46,7 @@ class Table {
4446 * @param array $rows The rows of data for this table. Optional.
4547 * @param array $footers Footers used in this table. Optional.
4648 */
47- public function __construct (array $ headers = null , array $ rows = null , array $ footers = null ) {
49+ public function __construct (array $ headers = null , array $ rows = null , array $ footers = null , $ alignments = [] ) {
4850 if (!empty ($ headers )) {
4951 // If all the rows is given in $headers we use the keys from the
5052 // first row for the header values
@@ -62,6 +64,8 @@ public function __construct(array $headers = null, array $rows = null, array $fo
6264 $ this ->setRows ($ rows );
6365 }
6466
67+ $ this ->setAlignments ($ alignments );
68+
6569 if (!empty ($ footers )) {
6670 $ this ->setFooters ($ footers );
6771 }
@@ -79,6 +83,7 @@ public function resetTable()
7983 $ this ->_width = array ();
8084 $ this ->_rows = array ();
8185 $ this ->_footers = array ();
86+ $ this ->_alignments = array ();
8287 return $ this ;
8388 }
8489
@@ -137,6 +142,7 @@ public function display() {
137142 */
138143 public function getDisplayLines () {
139144 $ this ->_renderer ->setWidths ($ this ->_width , $ fallback = true );
145+ $ this ->_renderer ->setAlignments ($ this ->_alignments );
140146 $ border = $ this ->_renderer ->border ();
141147
142148 $ out = array ();
@@ -201,6 +207,15 @@ public function setFooters(array $footers) {
201207 $ this ->_footers = $ this ->checkRow ($ footers );
202208 }
203209
210+ /**
211+ * Set the alignments of the table.
212+ *
213+ * @param array $alignments An array of strings containing column alignments.
214+ */
215+ public function setAlignments (array $ alignments ) {
216+ $ this ->_alignments = $ alignments ;
217+ //TODO: Implement error if alignment is not valid and field is not valid
218+ }
204219
205220 /**
206221 * Add a row to the table.
0 commit comments