[Solar-svn] Revision 3290
pmjones at solarphp.com
pmjones at solarphp.com
Thu Jul 31 16:02:19 CDT 2008
Solar_Sql_Adapter, Solar_Sql_Adapter_Mysql, Solar_Sql_Adapter_Sqlite:
Various internal refactorings to make extension somewhat easier. May break
custom vendor adapters.
* [CHG] Rename method _dsn() to _buildDsn()
* [ADD] Method _setDsn() to set the DSN (internal-only)
* [ADD] Method setCacheKeyPrefix()
Modified: trunk/Solar/Sql/Adapter/Mysql.php
===================================================================
--- trunk/Solar/Sql/Adapter/Mysql.php 2008-07-31 16:38:32 UTC (rev 3289)
+++ trunk/Solar/Sql/Adapter/Mysql.php 2008-07-31 21:02:16 UTC (rev 3290)
@@ -121,38 +121,38 @@
* @return string A PDO-style DSN.
*
*/
- protected function _dsn()
+ protected function _buildDsn($info)
{
+ // the dsn info
$dsn = array();
// socket, or host-and-port? (can't use both.)
- if (! empty($this->_config['sock'])) {
+ if (! empty($info['sock'])) {
// use a socket
- $dsn[] = 'unix_socket=' . $this->_config['sock'];
+ $dsn[] = 'unix_socket=' . $info['sock'];
} else {
// use host and port
- if (! empty($this->_config['host'])) {
- $dsn[] = 'host=' . $this->_config['host'];
+ if (! empty($info['host'])) {
+ $dsn[] = 'host=' . $info['host'];
}
- if (! empty($this->_config['port'])) {
- $dsn[] = 'port=' . $this->_config['port'];
+ if (! empty($info['port'])) {
+ $dsn[] = 'port=' . $info['port'];
}
}
// database name
- if (! empty($this->_config['name'])) {
- $dsn[] = 'dbname=' . $this->_config['name'];
+ if (! empty($info['name'])) {
+ $dsn[] = 'dbname=' . $info['name'];
}
+ // done
return $this->_pdo_type . ':' . implode(';', $dsn);
}
-
-
/**
*
Modified: trunk/Solar/Sql/Adapter/Sqlite.php
===================================================================
--- trunk/Solar/Sql/Adapter/Sqlite.php 2008-07-31 16:38:32 UTC (rev 3289)
+++ trunk/Solar/Sql/Adapter/Sqlite.php 2008-07-31 21:02:16 UTC (rev 3290)
@@ -105,7 +105,7 @@
* @return string A PDO-style DSN.
*
*/
- protected function _dsn()
+ protected function _buildDsn()
{
$dsn = array();
if (! empty($this->_config['name'])) {
@@ -114,6 +114,13 @@
return $this->_pdo_type . ':' . implode(';', $dsn);
}
+ /**
+ *
+ * After connection, set various connection attributes.
+ *
+ * @return void
+ *
+ */
protected function _postConnect()
{
parent::_postConnect();
Modified: trunk/Solar/Sql/Adapter.php
===================================================================
--- trunk/Solar/Sql/Adapter.php 2008-07-31 16:38:32 UTC (rev 3289)
+++ trunk/Solar/Sql/Adapter.php 2008-07-31 21:02:16 UTC (rev 3290)
@@ -272,44 +272,70 @@
public function __construct($config = null)
{
parent::__construct($config);
- $this->_cache = Solar::dependency('Solar_Cache', $this->_config['cache']);
+
+ // set the DSN from the config info
+ $this->_setDsn();
+
+ // turn on profiling?
$this->setProfiling($this->_config['profiling']);
- // build a DSN
- $this->_dsn = $this->_dsn();
+ // set a cache object
+ $this->_cache = Solar::dependency(
+ 'Solar_Cache',
+ $this->_config['cache']
+ );
- // save the cache-key prefix
- $this->_cache_key_prefix = get_class($this) . '/' . md5($this->_dsn);
+ // set the cache-key prefix
+ $this->_setCacheKeyPrefix();
}
/**
*
- * Gets the connection-specific cache key prefix.
+ * Turns profiling on and off.
*
- * @return string
+ * @param bool $flag True to turn profiling on, false to turn it off.
*
+ * @return void
+ *
*/
- public function getCacheKeyPrefix()
+ public function setProfiling($flag)
{
- return $this->_cache_key_prefix;
+ $this->_profiling = (bool) $flag;
}
/**
*
- * Turns profiling on and off.
+ * Sets the connection-specific cache key prefix.
*
- * @param bool $flag True to turn profiling on, false to turn it off.
+ * @param string $prefix The cache-key prefix. When null, defaults to
+ * the class name, a slash, and the md5() of the DSN.
*
- * @return void
+ * @return string
*
*/
- public function setProfiling($flag)
+ public function setCacheKeyPrefix($prefix = null)
{
- $this->_profiling = (bool) $flag;
+ if ($prefix === null) {
+ $prefix = get_class($this) . '/' . md5($this->_dsn);
+ }
+
+ $this->_cache_key_prefix = $prefix;
}
/**
*
+ * Gets the connection-specific cache key prefix.
+ *
+ * @return string
+ *
+ */
+ public function getCacheKeyPrefix()
+ {
+ return $this->_cache_key_prefix;
+ }
+
+ /**
+ *
* Get the query profile array.
*
* @return array An array of queries executed by the adapter.
@@ -333,7 +359,6 @@
return $this->_pdo;
}
-
// -----------------------------------------------------------------
//
// Connection and basic queries
@@ -342,27 +367,41 @@
/**
*
+ * Sets the DSN value for the connection from the config info.
+ *
+ * @return void
+ *
+ */
+ protected function _setDsn()
+ {
+ $this->_dsn = $this->_buildDsn($this->_config);
+ }
+
+ /**
+ *
* Creates a PDO-style DSN.
*
* For example, "mysql:host=127.0.0.1;dbname=test"
*
- * @return string A PDO-style DSN.
+ * @param array $info An array with host, post, name, etc. keys.
*
+ * @return void
+ *
*/
- protected function _dsn()
+ protected function _buildDsn($info)
{
$dsn = array();
- if (! empty($this->_config['host'])) {
- $dsn[] = 'host=' . $this->_config['host'];
+ if (! empty($info['host'])) {
+ $dsn[] = 'host=' . $info['host'];
}
- if (! empty($this->_config['port'])) {
- $dsn[] = 'port=' . $this->_config['port'];
+ if (! empty($info['port'])) {
+ $dsn[] = 'port=' . $info['port'];
}
- if (! empty($this->_config['name'])) {
- $dsn[] = 'dbname=' . $this->_config['name'];
+ if (! empty($info['name'])) {
+ $dsn[] = 'dbname=' . $info['name'];
}
return $this->_pdo_type . ':' . implode(';', $dsn);
More information about the Solar-svn
mailing list