本文整理汇总了PHP中JO_Db::dbAdapter_name方法的典型用法代码示例。如果您正苦于以下问题:PHP JO_Db::dbAdapter_name方法的具体用法?PHP JO_Db::dbAdapter_name怎么用?PHP JO_Db::dbAdapter_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JO_Db
的用法示例。
在下文中一共展示了JO_Db::dbAdapter_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
/**
* Factory for JO_Db_Adapter_Abstract classes.
*
* First argument may be a string containing the base of the adapter class
* name, e.g. 'Mysqli' corresponds to class JO_Db_Adapter_Mysqli. This
* name is currently case-insensitive, but is not ideal to rely on this behavior.
* If your class is named 'My_Company_Pdo_Mysql', where 'My_Company' is the namespace
* and 'Pdo_Mysql' is the adapter name, it is best to use the name exactly as it
* is defined in the class. This will ensure proper use of the factory API.
*
* First argument may alternatively be an object of type JO_Config.
* The adapter class base name is read from the 'adapter' property.
* The adapter config parameters are read from the 'params' property.
*
* Second argument is optional and may be an associative array of key-value
* pairs. This is used as the argument to the adapter constructor.
*
* If the first argument is of type JO_Config, it is assumed to contain
* all parameters, and the second argument is ignored.
*
* @param mixed $adapter String name of base adapter class, or JO_Config object.
* @param mixed $config OPTIONAL; an array or JO_Config object with adapter parameters.
* @return JO_Db_Adapter_Abstract
* @throws JO_Db_Exception
*/
public static function factory($adapter, $config = array())
{
if ($config instanceof JO_Config) {
$config = $config->toArray();
}
/*
* Convert JO_Config argument to plain string
* adapter name and separate config object.
*/
if ($adapter instanceof JO_Config) {
if (isset($adapter->params)) {
$config = $adapter->params->toArray();
}
if (isset($adapter->adapter)) {
$adapter = (string) $adapter->adapter;
} else {
$adapter = null;
}
}
/*
* Verify that adapter parameters are in an array.
*/
if (!is_array($config)) {
/**
* @see JO_Db_Exception
*/
require_once 'JO/Db/Exception.php';
throw new JO_Db_Exception('Adapter parameters must be in an array or a JO_Config object');
}
/*
* Verify that an adapter name has been specified.
*/
if (!is_string($adapter) || empty($adapter)) {
/**
* @see JO_Db_Exception
*/
require_once 'JO/Db/Exception.php';
throw new JO_Db_Exception('Adapter name must be specified in a string');
}
/*
* Form full adapter class name
*/
$adapterNamespace = 'JO_Db_Adapter';
if (isset($config['adapterNamespace'])) {
if ($config['adapterNamespace'] != '') {
$adapterNamespace = $config['adapterNamespace'];
}
unset($config['adapterNamespace']);
}
// Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606
$adapterName = $adapterNamespace . '_';
$adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter))));
/*
* Load the adapter class. This throws an exception
* if the specified class cannot be loaded.
*/
if (!class_exists($adapterName)) {
require_once 'JO/Loader.php';
JO_Loader::loadClass($adapterName);
}
/*
* Create an instance of the adapter class.
* Pass the config to the adapter class constructor.
*/
self::$dbAdapter_name = $adapterName;
self::$dbAdapter = new $adapterName($config);
/*
* Verify that the object created is a descendent of the abstract adapter type.
*/
if (!self::$dbAdapter instanceof JO_Db_Adapter_Abstract) {
/**
* @see JO_Db_Exception
*/
require_once 'JO/Db/Exception.php';
throw new JO_Db_Exception("Adapter class '{$adapterName}' does not extend JO_Db_Adapter_Abstract");
//.........这里部分代码省略.........