protected function parse() { $this->models = []; foreach ($this->modelStrs as $str) { $scanner = new StringScanner($str); $model = []; $model['name'] = $scanner->scan('/\\w+/'); $model['fields'] = $scanner->scan('/\\[([^\\]]+)\\]/') ? preg_split('/\\s*,\\s*/', $scanner->getCapture(0)) : null; $model['alias'] = $scanner->scanUntil('/\\s*as (\\w+)/i') ? $scanner->getCapture(0) : $model['name']; $this->models[] = $model; } }
protected function parse() { $this->models = []; foreach ($this->modelStrs as $str) { $scanner = new StringScanner($str); $model = []; $model['name'] = $scanner->scan('/\\w+/'); $getFirstMatch = $scanner->scan('/\\[([^\\]]+)\\]/') ? $scanner->getCapture(0) : null; $getSecondMatch = $scanner->scan('/\\[([\\d]*)\\]/') ? $scanner->getCapture(0) : null; if ($getSecondMatch === null && (is_numeric($getFirstMatch) || empty($getFirstMatch))) { list($getSecondMatch, $getFirstMatch) = array($getFirstMatch, null); } $model['match'] = $getFirstMatch; $model['limit'] = (int) ($getSecondMatch ?: ($getSecondMatch === null ? 1 : 20)); $model['alias'] = $scanner->scanUntil('/\\s*as (\\w+)/i') ? $scanner->getCapture(0) : $model['name']; $model['order'] = $scanner->scanUntil('/\\s*order by (.+)$/i') ? $scanner->getCapture(0) : ''; $model['single'] = $getSecondMatch === null; if ($match = $model['match']) { $scanner = new StringScanner($match); $col = $scanner->scanUntil('/["\']?(.+?)["\']?\\s*\\=\\s*/') ? $scanner->getCapture(0) : null; $value = $scanner->scanUntil('/\\|\\|\\s*/') ?: $scanner->scanUntil('/(.*)$/'); if (preg_match('/(\\w+)\\.(\\w+)/', $value, $cols)) { $model['matchInfo'] = ['type' => 'relational', 'column' => $col ?: $cols[2], 'parent' => $cols[1], 'key' => $cols[2]]; } elseif (preg_match('/\\$(\\w+)/', $value, $glob)) { $model['matchInfo'] = ['type' => 'var', 'col' => $col ?: $glob[1], 'name' => $glob[1]]; } elseif (preg_match('/^(?:[\\"\'])(\\w+)(?:[\\"\'])$/', $value, $placeholder)) { $model['matchInfo'] = ['type' => 'string', 'col' => $col ?: $placeholder[1], 'value' => $placeholder[1]]; } elseif (preg_match('/(\\w+)/', $value, $placeholder)) { $model['matchInfo'] = ['type' => 'url_param', 'col' => $col ?: $placeholder[1], 'name' => $placeholder[1]]; } if (!$scanner->hasTerminated()) { $model['matchInfo']['default'] = $scanner->scan('/([\\"\'])(.*?)\\1$/') ? $scanner->getCapture(1) : $scanner->getRemainder(); } } $this->models[] = $model; } }