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

Commit

Permalink
PR #4364
Browse files Browse the repository at this point in the history
Merge branch 'hotfix/abstract-manager-prefix-removal' of git://github.com/weierophinney/zf2 into weierophinney-hotfix/abstract-manager-prefix-removal
  • Loading branch information
Ralph Schindler committed Apr 30, 2013
2 parents 693c65c + 2edc6cc commit 6d3f65a
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 202 deletions.
59 changes: 0 additions & 59 deletions library/Zend/Cache/Service/StorageCacheAbstractFactory.php

This file was deleted.

88 changes: 88 additions & 0 deletions library/Zend/Cache/Service/StorageCacheAbstractServiceFactory.php
@@ -0,0 +1,88 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Service;

use Zend\Cache\StorageFactory;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Storage cache factory for multiple caches.
*/
class StorageCacheAbstractServiceFactory implements AbstractFactoryInterface
{
/**
* @var array
*/
protected $config;

/**
* Configuration key for cache objects
*
* @var string
*/
protected $configKey = 'caches';

/**
* @param ServiceLocatorInterface $services
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
{
$config = $this->getConfig($services);
if (empty($config)) {
return false;
}

return (isset($config[$requestedName]) && is_array($config[$requestedName]));
}

/**
* @param ServiceLocatorInterface $services
* @param string $name
* @param string $requestedName
* @return \Zend\Cache\Storage\StorageInterface
*/
public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
{
$config = $this->getConfig($services);
$config = $config[$requestedName];
return StorageFactory::factory($config);
}

/**
* Retrieve cache 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[$this->configKey])) {
$this->config = array();
return $this->config;
}

$this->config = $config[$this->configKey];
return $this->config;
}
}
78 changes: 69 additions & 9 deletions library/Zend/Db/Adapter/AdapterAbstractServiceFactory.php
Expand Up @@ -15,25 +15,85 @@
/**
* Database adapter abstract service factory.
*
* Allow configure several database instances (writer and reader).
* Allows configuring several database instances (such as writer and reader).
*/
class AdapterAbstractServiceFactory implements AbstractFactoryInterface
{
/**
* @see \Zend\ServiceManager\AbstractFactoryInterface::canCreateServiceWithName()
* @var array
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
protected $config;

/**
* Can we create an adapter by the requested name?
*
* @param ServiceLocatorInterface $services
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
{
$config = $serviceLocator->get('Config');
return isset($config['db']['adapters'][$requestedName]);
$config = $this->getConfig($services);
if (empty($config)) {
return false;
}

return (
isset($config[$requestedName])
&& is_array($config[$requestedName])
&& !empty($config[$requestedName])
);
}

/**
* @see \Zend\ServiceManager\AbstractFactoryInterface::createServiceWithName()
* Create a DB adapter
*
* @param ServiceLocatorInterface $services
* @param string $name
* @param string $requestedName
* @return Adapter
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
{
$config = $serviceLocator->get('Config');
return new Adapter($config['db']['adapters'][$requestedName]);
$config = $this->getConfig($services);
return new Adapter($config[$requestedName]);
}

/**
* 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;
}
}
4 changes: 2 additions & 2 deletions library/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php
Expand Up @@ -119,7 +119,7 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa
if ($parameterContainer) {
if ($this->limit === null) {
array_push($sqls, ') b ) WHERE b_rownum > (:offset)');
$parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER);
$parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER);
} else {
// create bottom part of query, with offset and limit using row_number
array_push($sqls, ') b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)');
Expand All @@ -129,7 +129,7 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa
} else {
if ($this->limit === null) {
array_push($sqls, ') b ) WHERE b_rownum > ('. (int) $this->offset. ')'
);
);
} else {
array_push($sqls, ') b WHERE rownum <= ('
. (int) $this->offset
Expand Down
Expand Up @@ -13,22 +13,22 @@
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class FormAbstractFactory implements AbstractFactoryInterface
class FormAbstractServiceFactory implements AbstractFactoryInterface
{
/**
* @var string Top-level configuration key indicating forms configuration
* @var array
*/
protected $configKey = 'form_manager';
protected $config;

/**
* @var Factory Form factory used to create forms
* @var string Top-level configuration key indicating forms configuration
*/
protected $factory;
protected $configKey = 'forms';

/**
* @var string Service prefix necessary for abstract factory to trigger
* @var Factory Form factory used to create forms
*/
protected $servicePrefix = 'Form\\';
protected $factory;

/**
* Can we create the requested service?
Expand All @@ -40,36 +40,12 @@ class FormAbstractFactory implements AbstractFactoryInterface
*/
public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $rName)
{
if (!$services->has('Config')) {
return false;
}

$prefixLength = strlen($this->servicePrefix);
if (strlen($rName) < $prefixLength
|| substr($rName, 0, $prefixLength) !== $this->servicePrefix
) {
return false;
}

$config = $services->get('Config');
if (!isset($config[$this->configKey])
|| !is_array($config[$this->configKey])
|| empty($config[$this->configKey])
) {
return false;
}

$config = $config[$this->configKey];

$serviceName = substr($rName, $prefixLength);
if (!isset($config[$serviceName])
|| !is_array($config[$serviceName])
|| empty($config[$serviceName])
) {
$config = $this->getConfig($services);
if (empty($config)) {
return false;
}

return true;
return (isset($config[$rName]) && is_array($config[$rName]) && !empty($config[$rName]));
}

/**
Expand All @@ -82,17 +58,43 @@ public function canCreateServiceWithName(ServiceLocatorInterface $services, $nam
*/
public function createServiceWithName(ServiceLocatorInterface $services, $name, $rName)
{
$serviceName = substr($rName, strlen($this->servicePrefix));
$config = $services->get('Config');

$config = $config[$this->configKey][$serviceName];

$config = $this->getConfig($services);
$config = $config[$rName];
$factory = $this->getFormFactory($services);
$this->marshalInputFilter($config, $services, $factory);

$this->marshalInputFilter($config, $services, $factory);
return $factory->createForm($config);
}

/**
* Get forms 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[$this->configKey])
|| !is_array($config[$this->configKey])
) {
$this->config = array();
return $this->config;
}

$this->config = $config[$this->configKey];
return $this->config;
}

/**
* Retrieve the form factory, creating it if necessary
*
Expand Down

0 comments on commit 6d3f65a

Please sign in to comment.