Skip to content

Commit

Permalink
move logic "get Platform object" in to a seperate methode
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensSahs committed Jan 22, 2013
1 parent 72a9eec commit d2d1514
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions library/Zend/Mvc/Service/DbAdapterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

namespace Zend\Mvc\Service;


use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Platform\Platform;
use Zend\Mvc\Service\Exception\DbAdapterManagerAdapterAllreadyRegistered;
use Zend\Mvc\Service\Exception\DbAdapterManagerAdapterCoundInit;
use Zend\Mvc\Service\Exception\DbAdapterManagerAdapterNotExist;
use Zend\Mvc\Service\Exception\DbAdapterManagerAdapterConfigNotVaild;

use Exception;

class DbAdapterManager implements ServiceLocatorAwareInterface
Expand Down Expand Up @@ -173,6 +174,43 @@ protected function initAdapter($key)
return $this->_dbAdapter[ $key ];
}

/**
* return a platform object from a config
*
* @param array $config
* @param ServiceLocatorInterface $serviceLocator
* @return Platform || null
*/
protected function getPlatformObjectFromConfig ($config, ServiceLocatorInterface $serviceLocator=null)
{
if ( !isset($config['platform']) ) {
goto RETURN_NULL;
}

if ( is_string ($config['platform']) ) {
if( class_exists($config['platform']) ) {
$platform = new $config['platform']();
} else {
if ( $serviceLocator === null ) {
$serviceLocator = $this->getServiceLocator();
}
$platform = $serviceLocator->get($config['platform']);
}
} else {
$platform = $config['platform'];
}

if ( is_object($platform) ) {
goto RETURN_OBJECT;
}

RETURN_NULL:
return null;

RETURN_OBJECT:
return $platform;
}

/**
* @param array $config
* @param ServiceLocatorInterface $serviceLocator
Expand Down Expand Up @@ -207,17 +245,7 @@ public function adapterFactory($config, ServiceLocatorInterface $serviceLocator=
}
}

if ( isset($config['platform']) ) {
if( class_exists($config['platform']) ) {
$platform = new $config['platform']();
} else {
$platform = $serviceLocator->get($config['platform']);
}
}

if ( !is_object($platform) ) {
$platform = null;
}
$platform = $this->getPlatformObejctFromConfig($config,$serviceLocator);

if ( isset($config['queryResultPrototype']) ) {
if( class_exists($config['queryResultPrototype']) ) {
Expand Down

0 comments on commit d2d1514

Please sign in to comment.