public static function query($query) { $shortq = preg_replace('/\\s*/m', '', $query); if (!self::$cachedStatements[$shortq] instanceof statement) { $lexer = new lexer(); $parsedQuery = $lexer->parse($query); $statement = new statement(); $statement->setQuery($parsedQuery); $datastore = $parsedQuery->getModel()->getDatastore(); $driverclass = '\\Moya\\core\\orm\\drivers\\' . config::get('datastore', $datastore . '/driver'); $driver = $driverclass::getInstance($datastore); $statement->setDriver($driver); $statement->setCompiledquery($driver->compileQuery($parsedQuery)); echo $statement->getCompiledquery() . "\n"; self::$cachedStatements[$shortq] = $statement->prepare(); } return self::$cachedStatements[$shortq]; }
protected function parseField(lexer $lexer) { $lexer->moveNext(); $object = ''; if ($lexer->isNextToken('.')) { $modelclass = inflector::getModelfromcontext($lexer->getCurrentToken()); $model = new $modelclass(); $lexer->moveNext(); $lexer->moveNext(); } else { $model = $lexer->query->getModel(); } $field = $lexer->getCurrentToken(); if (!$lexer->isNextToken(']')) { throw new \Exception('Invalid query syntax: Expected \']\' after ' . $lexer->getCurrentToken()); } $lexer->moveNext(); $lexer->moveNext(); return array('model' => $model, 'field' => $field); }