/** * @param string $str * @return NQLQuery * @throws SyntaxErrorException */ public static function parse($str) : NQLQuery { /** @var NQLQuery $query */ $query = new NQLQuery(); $match = []; $wasFound = preg_match(self::$regSearchQuery, $str, $match); if ($wasFound) { if (array_key_exists('select', $match) && !empty($match['select'])) { $query->select = Select::parse($match['select']); } else { $query->select = Select::getBlank(); } if (array_key_exists('where', $match)) { $query->where = Where::parse($match['where']); } else { $query->where = Where::getBlank(); } if (array_key_exists('limit', $match) && !empty($match['limit'])) { $query->limit = $match['limit']; } if (array_key_exists('offset', $match) && !empty($match['offset'])) { $query->offset = $match['offset']; } $query->from = From::parse($match['from']); if (array_key_exists('orderby', $match) && !empty($match['orderby'])) { $query->orderBy = OrderBy::parse($match['orderby']); } else { $query->orderBy = OrderBy::getBlank(); } } else { throw new SyntaxErrorException('Incorrect query'); } return $query; }
/** * @param From $from * @throws SyntaxErrorException */ private function checkTables(From $from) { $tables = $from->getTables(); foreach ($tables as $table) { if (!array_key_exists(strtolower($table->getName()), $this->entities)) { throw new SyntaxErrorException("Unknown table \"{$table->getName()}\""); } } }