1+ <?php
2+
3+ namespace splitbrain \phpcli \examples ;
4+
5+ require __DIR__ . '/../vendor/autoload.php ' ;
6+
7+ use splitbrain \phpcli \CLI ;
8+ use splitbrain \phpcli \Colors ;
9+ use splitbrain \phpcli \Options ;
10+ use splitbrain \phpcli \TableFormatter ;
11+
12+ class Table extends CLI
13+ {
14+
15+ /**
16+ * Register options and arguments on the given $options object
17+ *
18+ * @param Options $options
19+ * @return void
20+ */
21+ protected function setup (Options $ options )
22+ {
23+ $ options ->setHelp ('This shows how the table formatter works by printing the current php.ini values ' );
24+ }
25+
26+ /**
27+ * Your main program
28+ *
29+ * Arguments and options have been parsed when this is run
30+ *
31+ * @param Options $options
32+ * @return void
33+ */
34+ protected function main (Options $ options )
35+ {
36+ $ tf = new TableFormatter ($ this ->colors );
37+ $ tf ->setBorder (' | ' ); // nice border between colmns
38+
39+ // show a header
40+ echo $ tf ->format (
41+ array ('* ' , '30% ' , '30% ' ),
42+ array ('ini setting ' , 'global ' , 'local ' )
43+ );
44+
45+ // a line across the whole width
46+ echo str_pad ('' , $ tf ->getMaxWidth (), '- ' ) . "\n" ;
47+
48+ // colored columns
49+ $ ini = ini_get_all ();
50+ foreach ($ ini as $ val => $ opts ) {
51+ echo $ tf ->format (
52+ array ('* ' , '30% ' , '30% ' ),
53+ array ($ val , $ opts ['global_value ' ], $ opts ['local_value ' ]),
54+ array (Colors::C_CYAN , Colors::C_RED , Colors::C_GREEN )
55+ );
56+ }
57+ }
58+ }
59+
60+ $ cli = new Table ();
61+ $ cli ->run ();
0 commit comments