Permalink
Browse files

Renamed class name and updated README

  • Loading branch information...
fedecarg committed Mar 4, 2012
1 parent 8ee999a commit f9212db2d2f8314dd491ab52d540aae5e0955443
Showing with 34 additions and 17 deletions.
  1. +28 −7 README.md
  2. +6 −10 src/DataSource.php
View
@@ -86,15 +86,19 @@ Database connections are expensive and it's very inefficient for an application
To enable this option, you have to pass an instance of the Memcached adapter class:
```php
+<<<<<<< HEAD
<?php
class Bootstrap extends Zend_Application_Bootstrap_Base {
+=======
+class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
+>>>>>>> Renamed class name and updated README
- protected function _initCache() {
- ...
+ public function _initCache() {
+ // ...
}
- protected function _initDatabase() {
+ protected function _initDataSource() {
$config = include APPLICATION_PATH . '/config/database.php';
$dataSource = new Zf_Orm_DataSource($config, $this->getResource('cache'), 'cache_tag');
Zend_Registry::set('dataSource', $dataSource);
@@ -105,18 +109,29 @@ class Bootstrap extends Zend_Application_Bootstrap_Base {
And here is a short example of how the Replication Adapter might be used in a ZF application:
```php
+<<<<<<< HEAD
<?php
class TestDao {
+=======
+abstract class Dao {
+>>>>>>> Renamed class name and updated README
- public function select() {
- $db = Zend_Registry::get('dataSource')->getConnection('slave');
+ public function getConnection($server) {
+ return Zend_Registry::get('dataSource')->getConnection($server);
+ }
+}
+
+class TestDao extends Dao {
+
+ public function findAll() {
+ $db = $this->getConnection('slave');
$query = $db->select()->from('test');
return $db->fetchAll($query);
}
- public function insert($data) {
- $db = Zend_Registry::get('dataSource')->getConnection('master');
+ public function save($data) {
+ $db = $this->getConnection('master');
$db->insert('test', $data);
return $db->lastInsertId();
}
@@ -125,5 +140,11 @@ class TestDao {
## License
+<<<<<<< HEAD
- New BSD License http://www.opensource.org/licenses/bsd-license.php
- Copyright (c) 2008, Federico Cargnelutti. All rights reserved.
+=======
+* Copyright (c) 2010, Federico Cargnelutti. All rights reserved
+* New BSD License http://www.opensource.org/licenses/bsd-license.php
+
+>>>>>>> Renamed class name and updated README
View
@@ -28,25 +28,21 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * @category Zf
- * @package Zf_Orm
* @author Federico Cargnelutti <fedecarg@gmail.com>
* @copyright Copyright (c) 2010 Federico Cargnelutti
* @license New BSD License
* @version $Id: $
*/
/**
- * @category Zf
- * @package Zf_Orm
* @author Federico Cargnelutti <fedecarg@gmail.com>
* @copyright Copyright (c) 2010 Federico Cargnelutti
* @license New BSD License
* @version $Id: $
*/
-class Zf_Orm_DataSourceException extends Zf_Orm_Exception {}
+class DataSourceException extends Exception {}
-class Zf_Orm_DataSource
+class DataSource
{
const SUPPLIER_SERVER = 'master';
const CONSUMER_SERVER = 'slave';
@@ -171,7 +167,7 @@ public function setConnection(Zend_Db_Adapter_Abstract $conn, $server)
*
* @param string $server master (supplier) or slave (consumer)
* @return Zend_Db_Adapter_Abstract
- * @throws Zf_Orm_DataSourceException
+ * @throws DataSourceException
*/
public function getConnection($server)
{
@@ -199,7 +195,7 @@ public function getConnection($server)
$failed[] = $key;
$this->getCache()->save(array_unique($failed), $failedCacheKey, array(), 30);
}
- throw new Zf_Orm_DataSourceException(sprintf('Unable to connect to "%s" server', $server));
+ throw new DataSourceException(sprintf('Unable to connect to "%s" server', $server));
}
/**
@@ -240,14 +236,14 @@ public function createConnection($server)
*
* @param Zend_Db_Adapter_Abstract $adapter
* @return boolean
- * @throws Zf_Orm_DataSourceException
+ * @throws DataSourceException
*/
public function isConnected(Zend_Db_Adapter_Abstract $adapter)
{
try {
return ($adapter->getConnection()) ? true : false;
} catch (Zend_Exception $e) {
- throw new Zf_Orm_DataSourceException($e->getMessage());
+ throw new DataSourceException($e->getMessage());
}
}

0 comments on commit f9212db

Please sign in to comment.