config = array( 'limit' => 0, 'dynfilters' => false, 'summarize' => false, 'rownumbers' => false, 'sepbyheaders' => false, 'headers' => array(), 'widths' => array(), 'filter' => array(), 'schemas' => array(), 'sort' => array() ); // parse info foreach($lines as $line) { list($key, $val) = $this->splitLine($line); if(!$key) continue; $logic = 'OR'; // handle line commands (we allow various aliases here) switch($key) { case 'from': case 'schema': case 'tables': $this->config['schemas'] = array_merge($this->config['schemas'], $this->parseSchema($val)); break; case 'select': case 'cols': case 'field': case 'col': $this->config['cols'] = $this->parseValues($val); break; case 'title': $this->config['title'] = $val; break; case 'head': case 'header': case 'headers': $this->config['headers'] = $this->parseValues($val); break; case 'align': $this->config['align'] = $this->parseAlignments($val); break; case 'width': case 'widths': $this->config['widths'] = $this->parseWidths($val); break; case 'min': $this->config['min'] = abs((int) $val); break; case 'limit': case 'max': $this->config['limit'] = abs((int) $val); break; case 'order': case 'sort': // FIXME multiple values!? $this->config['sort'][] = $helper->parseSort($val); break; case 'where': case 'filter': case 'filterand': /** @noinspection PhpMissingBreakStatementInspection */ case 'and': $logic = 'AND'; case 'filteror': case 'or': $flt = $helper->parseFilterLine($logic, $val); if($flt) { $this->config['filter'][] = $flt; } break; case 'page': case 'target': $this->config['page'] = cleanID($val); break; case 'dynfilters': $this->config['dynfilters'] = (bool) $val; break; case 'rownumbers': $this->config['rownumbers'] = (bool) $val; break; case 'summarize': $this->config['summarize'] = (bool) $val; break; case 'sepbyheaders': $this->config['sepbyheaders'] = (bool) $val; break; default: throw new StructException("unknown option '%s'", hsc($val)); } } // fill up headers - a NULL signifies that the column label is wanted $this->config['headers'] = (array) $this->config['headers']; $cnth = count($this->config['headers']); $cntf = count($this->config['cols']); for($i = $cnth; $i < $cntf; $i++) { $this->config['headers'][] = null; } } /** * Get the parsed configuration * * @return array */ public function getConfig() { return $this->config; } /** * Splits the given line into key and value * * @param $line * @return bool|array returns false for empty lines */ protected function splitLine($line) { // ignore comments $line = preg_replace('/(? 0) { array_push($values, trim($value)); } return $values; } }