Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

feature for abstract factories #35

Closed
zsaltys opened this issue Aug 2, 2013 · 1 comment
Closed

feature for abstract factories #35

zsaltys opened this issue Aug 2, 2013 · 1 comment
Labels

Comments

@zsaltys
Copy link

zsaltys commented Aug 2, 2013

Hey,

You might want to include abstract service factory. Sorry I'm too lazy to do a patch so I'll just paste the code here:

getConfig($services); if (empty($config)) { return false; } return ( isset($config[$requestedName]) && is_array($config[$requestedName]) && !empty($config[$requestedName]) ); } /** * Create a DB adapter * * @param ServiceLocatorInterface $services * @param string $name * @param string $requestedName * @return Adapter */ public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) { $config = $this->getConfig($services); $dbParams = $config[$requestedName]; $adapter = new ProfilingAdapter($dbParams); $adapter->setProfiler(new Profiler); if (isset($dbParams['options']) && is_array($dbParams['options'])) { $options = $dbParams['options']; } else { $options = array(); } $adapter->injectProfilingStatementPrototype($options); return $adapter; } /** * Get db configuration, if any * * @param ServiceLocatorInterface $services * @return array */ protected function getConfig(ServiceLocatorInterface $services) { if ($this->config !== null) { return $this->config; } if (!$services->has('Config')) { $this->config = array(); return $this->config; } $config = $services->get('Config'); if (!isset($config['db']) || !is_array($config['db']) ) { $this->config = array(); return $this->config; } $config = $config['db']; if (!isset($config['adapters']) || !is_array($config['adapters']) ) { $this->config = array(); return $this->config; } $this->config = $config['adapters']; return $this->config; } ``` }
@DanielBeltran
Copy link

Since this issue is not solved till now and it is related to #47 i wanted to comment on this.

To implement multiple database adapters per abstract factory, till now it is only possible to implement one database due to developer tools Module.php:
'ZendDeveloperTools\DbCollector' => function ($sm) {
$p = false;
$db = new Collector\DbCollector();

                if ($sm->has('Zend\Db\Adapter\Adapter')) {
                    $adapter = $sm->get('Zend\Db\Adapter\Adapter');
                    if ($adapter instanceof ProfilingAdapter) {
                        $p = true;
                        $db->setProfiler($adapter->getProfiler());
                    }
                }
                if (!$p && $sm->has('Zend\Db\Adapter\ProfilingAdapter')) {
                    $adapter = $sm->get('Zend\Db\Adapter\ProfilingAdapter');
                    if ($adapter instanceof ProfilingAdapter) {
                        $db->setProfiler($adapter->getProfiler());
                    }
                }
                return $db;
            },

Since Developer Tools will only add Zend\Db\Adapter\Adapter.

To work around that problem DT have to be configured to accept multiple Profilers, and multiple instances of bjyprofiler have to be instantiated....

So the fix has to be here and in DT.

Maybe its possible to add a Profiler array? so Zend\Db\Adapter\Adapter gets an array of all Adapters configured in the abstractfactory of db Adapter...?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants