Permalink
Browse files

- move logic "get driver object" in to a seperate methode

- fix a typo
  • Loading branch information...
1 parent d2d1514 commit a48cfb0f9ddda7c28ac03c49c2c677d19b774d29 @ClemensSahs committed Jan 22, 2013
Showing with 41 additions and 19 deletions.
  1. +41 −19 library/Zend/Mvc/Service/DbAdapterManager.php
@@ -211,6 +211,45 @@ protected function getPlatformObjectFromConfig ($config, ServiceLocatorInterface
return $platform;
}
+ /**
+ * return a driver object from a config
+ *
+ * @param array $config
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return Platform || null
+ */
+ protected function getDriverObjectFromConfig ($config, ServiceLocatorInterface $serviceLocator=null)
+ {
+ if ( !isset($config['driver']) ) {
+ // @todo: throw a error or return null ?
+ goto RETURN_NULL;
+ }
+
+ if ( is_array($config['driver']) || is_object($config['driver']) ) {
+ $driver = $config['driver'];
+ } elseif ( is_string($config['driver']) ) {
+ if( class_exists($config['driver']) ) {
+ $driver = new $config['driver']();
+ } else {
+ $driver = $serviceLocator->get($config['driver']);
+ }
+
+ if ( !is_object($driver) ) {
+ throw new DbAdapterManagerAdapterConfigNotVaild("database config['driver'] string is not a confirmed class/service name");
+ }
+ } else {
+ throw new DbAdapterManagerAdapterConfigNotVaild("database config['driver'] must be a array or string of class/service name");
+ }
+
+ goto RETURN_OBJECT;
+
+ RETURN_NULL:
+ return null;
+
+ RETURN_OBJECT:
+ return $driver;
+ }
+
/**
* @param array $config
* @param ServiceLocatorInterface $serviceLocator
@@ -227,25 +266,8 @@ public function adapterFactory($config, ServiceLocatorInterface $serviceLocator=
$platform = null;
$queryResultPrototype = null;
- if ( isset($config['driver']) ) {
- if ( is_array($config['driver']) ) {
- $driver = $config['driver'];
- } elseif ( is_string($config['driver']) ) {
- if( class_exists($config['driver']) ) {
- $driver = new $config['driver']();
- } else {
- $driver = $serviceLocator->get($config['driver']);
- }
-
- if ( !is_object($platform) ) {
- throw new DbAdapterManagerAdapterConfigNotVaild("database config['driver'] string is not a confirmed class/service name");
- }
- } else {
- throw new DbAdapterManagerAdapterConfigNotVaild("database config['driver'] must be a array or string of class/service name");
- }
- }
-
- $platform = $this->getPlatformObejctFromConfig($config,$serviceLocator);
+ $driver = $this->getDriverObjectFromConfig($config,$serviceLocator);
+ $platform = $this->getPlatformObjectFromConfig($config,$serviceLocator);
if ( isset($config['queryResultPrototype']) ) {
if( class_exists($config['queryResultPrototype']) ) {

0 comments on commit a48cfb0

Please sign in to comment.