protected function setupAdapter($adapter) { if (!$adapter && !($adapter = $this->getAdapter()) && !($adapter = AdapterPool::get())) { throw new Exception\RuntimeException('Adapter must be setup'); } $this->setAdapter($adapter); }
/** * @param AdapterInterface $adapter * @param string|TableIdentifier $table */ public function __construct(AdapterInterface $adapter = null, $table = null) { if (!$adapter && !($adapter = AdapterPool::get())) { throw new Exception\RuntimeException('A adapter must be suplied'); } $this->adapter = $adapter; if ($table) { $this->setTable($table); } }
/** * 根据全局或者模块配置实例化数据操作对象 * * @access public * @param array $options * @param string $name * @return \Db\Adapter\AdapterInterface|null */ public static function db($options = array(), $name = AdapterPool::DEFAULT_ADAPTER) { if (AdapterPool::has($name)) { return AdapterPool::get($name); } if (!empty($options)) { } else { if (Registry::get("config") && Registry::get("config")->database_config instanceof Simple && ($options = Registry::get("config")->database_config->toArray())) { } else { if (isset(Application::app()->getConfig()->application->database)) { $options = Application::app()->getConfig()->application->database->toArray(); } } } $adapter = new Adapter($options); AdapterPool::register($adapter); return AdapterPool::get($name); }