Exemple #1
0
 public function createUser($id)
 {
     $key = 'user_' . $id;
     $user = Register::get($key);
     if ($user) {
         $user = new User($id);
         Register::set($key, $user);
     }
     return $user;
 }
 public static function getDataBase()
 {
     $db = Register::get('db');
     if (!$db) {
         // 单例模式
         $db = new Database\MySQLi();
         $db->connect('127.0.0.1', 'root', '123456', 'test');
         Register::set('db', $db);
     }
     return $db;
 }
 public function __construct($requiredAuthentication)
 {
     $this->requiredAuthentication = $requiredAuthentication;
     $this->id = Session::get('id');
     $this->login = Session::get('login');
     if (!empty($this->login) && !empty($this->id)) {
         $this->isLogged = true;
         Register::set('id', $this->id);
         Register::set('login', $this->login);
     } else {
         $this->isLogged = false;
     }
 }
Exemple #4
0
 /**
  * 数据库工厂方法
  */
 public static function getDatabase($id = 'master')
 {
     //读取数据库配置文件
     if ($id == 'master') {
         $db_conf = Init::getInstance()->config['DataBase']['master'];
     } else {
         $db_conf = Init::getInstance()->config['DataBase']['slave'];
     }
     $key = 'database_' . $id;
     //获取数据库对象
     $db = Register::get($key);
     if (!$db) {
         $db = new MySQLi();
         $db->connect($db_conf['host'], $db_conf['user'], $db_conf['password'], $db_conf['dbname']);
         Register::set($key, $db);
     }
     return $db;
 }
Exemple #5
0
 static function getDatabase($id = 'proxy')
 {
     if ($id == 'proxy') {
         if (!self::$proxy) {
             self::$proxy = new \IMooc\Database\Proxy();
         }
         return self::$proxy;
     }
     $key = 'database_' . $id;
     if ($id == 'slave') {
         $slaves = Application::getInstance()->config['database']['slave'];
         $db_conf = $slaves[array_rand($slaves)];
     } else {
         $db_conf = Application::getInstance()->config['database'][$id];
     }
     $db = Register::get($key);
     if (!$db) {
         $db = new Database\MySQLi();
         $db->connect($db_conf['host'], $db_conf['user'], $db_conf['password'], $db_conf['dbname']);
         Register::set($key, $db);
     }
     return $db;
 }
Exemple #6
0
 public static function getUser()
 {
     $user = new user();
     Register::set('user', $user);
     return $user;
 }
Exemple #7
0
 static function createDatabase()
 {
     $db = Database::getInstance();
     Register::set('db1', $db);
     return $db;
 }
// Configurações
require_once "_includes" . DIRSEP . "config.php";
#----- DOCTRINE -----#
require_once DOCTRINE_PATH . DIRECTORY_SEPARATOR . 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative');
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
#Doctrine_Manager::connection(DSN, 'sandbox');
$conn = Doctrine_Manager::connection("mysql://{$USER}:{$PASS}@{$HOST}/{$DB}");
#----- END_DOCTRINE -----#
Doctrine::loadModels(REAL_PATH . "model" . DIRSEP . "app");
// Carregando o mapeamento das classes
require_once "_includes" . DIRSEP . "class_mapping.php";
$reg = new Register();
// Instanciando o objeto Smarty
include REAL_PATH . "model" . DIRSEP . "thirdparty" . DIRSEP . "smarty" . DIRSEP . "libs" . DIRSEP . "Smarty.class.php";
// Objeto Smarty :)
$s = new Smarty();
$s->template_dir = REAL_PATH . "view" . DIRSEP;
$s->compile_dir = REAL_PATH . "model" . DIRSEP . "thirdparty" . DIRSEP . "smarty" . DIRSEP . "compiled_templates" . DIRSEP;
$s->config_dir = REAL_PATH . "model" . DIRSEP . "thirdparty" . DIRSEP . "smarty" . DIRSEP . "configs" . DIRSEP;
$s->cache_dir = REAL_PATH . "model" . DIRSEP . "thirdparty" . DIRSEP . "smarty" . DIRSEP . "cache" . DIRSEP;
//$s->load_filter('output','optmizer');
$s->left_delimiter = '{{';
$s->right_delimiter = '}}';
$s->compile_check = true;
$s->assign('BASE_URL', BASE_URL);
$s->assign('BASE_URLS', BASE_URLS);
// BASE_URL + HTTPS
$reg->set("s", $s);