/** * @ignore */ public function __construct() { $this->db = Datasources::get(); // default datasource to member 'db' $this->logger = new LoggerInstance(get_class($this)); $this->prerender = new Delegate(); $this->postrender = new Delegate(); $tReflection = new \ReflectionClass($this); foreach ($tReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $tMethodReflection) { if ($tMethodReflection->class === __CLASS__) { continue; } $tDocComment = $tMethodReflection->getDocComment(); if (strlen($tDocComment) > 0) { $this->annotations[$tMethodReflection->name] = Utils::parseAnnotations($tDocComment); } } }
/** * @ignore */ public static function open() { self::$datasource = Datasources::get(Config::get('session/datasource', 'fileCache')); self::$sessionName = Config::get('session/cookie/name', 'sessid'); if (Config::get('session/cookie/nameIp', true)) { self::$sessionName .= hash('adler32', $_SERVER['REMOTE_ADDR']); } self::$sessionTtl = Config::get('session/cookie/ttl', 0); if (isset($_COOKIE[self::$sessionName])) { self::$id = $_COOKIE[self::$sessionName]; } if (self::$id !== null) { $tIpCheck = Config::get('session/cookie/ipCheck', false); $tUACheck = Config::get('session/cookie/uaCheck', true); $tData = self::$datasource->cacheGet('sessions/' . self::$id); if ($tData !== false) { if ((!$tIpCheck || $tData['ip'] === $_SERVER['REMOTE_ADDR']) && (!$tUACheck || $tData['ua'] === $_SERVER['HTTP_USER_AGENT'])) { self::$data = $tData['data']; return; } } } self::$data = array(); }
/** * @ignore */ public function query($uQuery, array $uParameters = array(), $uCaching = null, $uModifies = false, $uSequence = null) { $this->connectionOpen(); $tPreDebugInfo = array('query' => $uQuery, 'parameters' => $uParameters); if (Framework::$development) { if ($uModifies) { $this->beginTransaction(); } if (!$uModifies || $this->explainOnModifies) { $tPreDebugInfo['explain'] = $this->queryArray(String::format($this->explainCommand, array('query' => $uQuery)), $uParameters); } if ($uModifies) { $this->rollBack(); } } $this->logger->profilerStart($this->id . ' query', 'query', $tPreDebugInfo); if (!Framework::$disableCaches && $uCaching !== null) { $tCaching = (array) $uCaching; if (!isset($tCaching[1])) { $tOld = array_merge((array) $uQuery, $uParameters); } else { $tOld = (array) $tCaching[1]; } if (!isset($tCaching[2])) { $tCaching[2] = 0; } $tCaching[1] = $this->id; $tCount = 0; foreach ($tOld as $tParameter) { $tCaching[1] .= ($tCount++ === 0 ? '/' : '_') . hash('adler32', $tParameter); } $tData = Datasources::get($tCaching[0])->cacheGet($tCaching[1]); if ($tData !== false) { $this->cache[$tCaching[1]] = $tData->resume($this); $tLoadedFromCache = true; } else { $tLoadedFromCache = false; } } else { $tCaching = null; $tData = false; $tLoadedFromCache = false; } if ($tData === false) { $tData = new DatabaseQueryResult($uQuery, $uParameters, $this, $tCaching, $uSequence); ++$this->stats['query']; } else { ++$this->stats['cache']; } //! affected rows $tPostDebugInfo = array('affectedRows' => $tData->count(), 'fromCache' => $tLoadedFromCache); $this->logger->profilerStop($tPostDebugInfo); return $tData; }
/** * @ignore */ public function setDatabaseName($uDatabaseName) { $this->database = Datasources::get($uDatabaseName); $this->clear(); }
/** * Allows authenticated users to log into the system * * @param string $uUsername username * @param string $uPassword password * * @return bool whether the user logged in or not */ public static function login($uUsername, $uPassword) { self::load(); if (self::$hash === 'md5') { $tPassword = md5($uPassword); } else { $tPassword = $uPassword; } if (self::$type === 'config') { foreach (Config::get('auth/userList', array()) as $tUser) { if ($uUsername !== $tUser['username'] || $tPassword !== $tUser['password']) { continue; } Session::set(self::$sessionKey, array('username' => $tUser['username'], 'roles' => isset(self::$user['roles']) ? $tUser['roles'] : self::$defaultRoles, 'extra' => $tUser)); return true; } } elseif (self::$type === 'database') { $tDatasource = Config::get('auth/database/datasource'); $tQuery = Config::get('auth/database/query'); $tPasswordField = Config::get('auth/database/passwordField'); $tDbConn = Datasources::get($tDatasource); $tResult = $tDbConn->query($tQuery, array('username' => $uUsername))->row(); if ($tResult !== false && isset($tResult[$tPasswordField]) && $tResult[$tPasswordField] === $tPassword) { Session::set(self::$sessionKey, array('username' => $uUsername, 'roles' => isset(self::$user['roles']) ? $tResult['roles'] : self::$defaultRoles, 'extra' => $tResult)); return true; } } // Session::remove(self::$sessionKey); return false; }
/** * @ignore */ public function __construct($uDatasource = null) { $this->db = Datasources::get($uDatasource); }
/** * @ignore */ public static function loadDatasource($uDatasourceName) { if (!isset(self::$models[$uDatasourceName])) { self::$models[$uDatasourceName] = Datasources::get($uDatasourceName); } return self::$models[$uDatasourceName]; }