Esempio n. 1
0
 function testResultIsMultiObj()
 {
     $arraysimple = array('name' => 'test', 'key' => 'test');
     $arraymultiobj = array(0 => (object) array('name' => 'test', 'key' => 'test'));
     $this->assertFalse(\Terminus\Utils\result_is_multiobj($arraysimple));
     $this->assertTrue(\Terminus\Utils\result_is_multiobj($arraymultiobj));
 }
Esempio n. 2
0
 /**
  * Constructs table for data going to STDOUT
  * TODO: Complexity too high. Refactor.
  *
  * @param [mixed] $data    Object or hash of data for output
  * @param [array] $headers Array of strings for table headers
  * @return [void]
  */
 protected function constructTableForResponse($data, $headers = array())
 {
     $table = new \cli\Table();
     if (is_object($data)) {
         $data = (array) $data;
     }
     if (\Terminus\Utils\result_is_multiobj($data)) {
         if (!empty($headers)) {
             $table->setHeaders($headers);
         } elseif (property_exists($this, '_headers') && !empty($this->_headers[$this->func])) {
             if (is_array($this->_headers[$this->func])) {
                 $table->setHeaders($this->_headers[$this->func]);
             }
         } else {
             $table->setHeaders(\Terminus\Utils\result_get_response_fields($data));
         }
         foreach ($data as $row => $row_data) {
             $row = array();
             foreach ($row_data as $key => $value) {
                 if (is_array($value) || is_object($value)) {
                     $value = join(', ', (array) $value);
                 }
                 $row[] = $value;
             }
             $table->addRow($row);
         }
     } else {
         if (!empty($headers)) {
             $table->setHeaders($headers);
         }
         foreach ($data as $key => $value) {
             if (is_array($value) || is_object($value)) {
                 $value = implode(', ', (array) $value);
             }
             $table->addRow(array($key, $value));
         }
     }
     $table->display();
 }