Esempio n. 1
0
File: Db.php Progetto: vzina/yaf-api
 public static function instance($name = null, array $config = array())
 {
     if (empty($name)) {
         $name = '_db';
     }
     /** 单例*/
     if (Registry::has($name)) {
         return Registry::get($name);
     }
     if (empty($config)) {
         /** @var \Yaf\Config\Ini $_config */
         $_config = Registry::get('config');
         if (!$_config || !($tmp = $_config->get($name))) {
             return false;
         }
         $config = $tmp->toArray();
     }
     if (empty($config['adapter'])) {
         $config['adapter'] = 'Pdo\\Mysql';
     }
     $db = Db::factory($config);
     Registry::set($name, $db);
     return $db;
 }
Esempio n. 2
0
 public static function instance($name, array $config = array())
 {
     if (empty($name)) {
         $name = '_cache';
     }
     /** 单例*/
     if (Registry::has($name)) {
         return Registry::get($name);
     }
     if (empty($config)) {
         /** @var \Yaf\Config\Ini $_config */
         $_config = Registry::get('config');
         if (!$_config || !($tmp = $_config->get($name))) {
             return false;
         }
         $config = $tmp->toArray();
     }
     if (empty($config['adapter'])) {
         $config['adapter'] = 'file';
     }
     $cache = self::factory($config);
     Registry::set($name, $cache);
     return $cache;
 }
Esempio n. 3
0
 /**
  * Dynamic get vars
  *
  * @param string $key
  * @return Models|mixed
  * @throws Exception
  */
 public function __get($key)
 {
     switch ($key) {
         case 'model':
             $class = get_class($this);
             $this->model = $this->model(substr($class, 0, -10));
             return $this->model;
         default:
             if (true == Registry::has($key)) {
                 $value = Registry::get($key);
                 if ($value instanceof \Closure) {
                     $value = call_user_func($value);
                 }
                 return $value;
             }
             throw new Exception('Undefined property: ' . get_class($this) . '::' . $key);
     }
 }