Skip to content
Browse files

Create factory for dbselect

  • Loading branch information...
1 parent 8c81500 commit 0adecd90578707017789f109c3c28a8fd6cc4896 @blanchonvincent blanchonvincent committed
View
46 library/Zend/Paginator/Adapter/Service/DbSelectFactory.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Paginator
+ */
+
+namespace Zend\Paginator\Adapter\Service;
+
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * @category Zend
+ * @package Paginator
+ */
+class DbSelectFactory implements FactoryInterface
+{
+ /**
+ * Adapter options
+ * @var array
+ */
+ protected $creationOptions;
+
+ /**
+ * Construct with adapter options
+ * @param array $creationOptions
+ */
+ public function __construct(array $creationOptions)
+ {
+ $this->creationOptions = $creationOptions;
+ }
+
+ /**
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return \Zend\Navigation\Navigation
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ $class = new \ReflectionClass('Zend\Paginator\Adapter\DbSelect');
+ return $class->newInstanceArgs($this->creationOptions);
+ }
+}
View
37 library/Zend/Paginator/AdapterPluginManager.php
@@ -31,38 +31,35 @@ class AdapterPluginManager extends AbstractPluginManager
*/
protected $invokableClasses = array(
'array' => 'Zend\Paginator\Adapter\ArrayAdapter',
- 'dbselect' => 'Zend\Paginator\Adapter\DbSelect',
'iterator' => 'Zend\Paginator\Adapter\Iterator',
'null' => 'Zend\Paginator\Adapter\Null',
);
/**
- * Attempt to create an instance via an invokable class
+ * Default set of adapter factories
*
- * Overrides parent implementation by passing $creationOptions to the
- * constructor, if non-null.
+ * @var array
+ */
+ protected $factories = array(
+ 'dbselect' => 'Zend\Paginator\Adapter\Service\DbSelectFactory'
+ );
+
+ /**
+ * Attempt to create an instance via a factory
*
* @param string $canonicalName
* @param string $requestedName
- * @return null|\stdClass
- * @throws Exception\ServiceNotCreatedException If resolved class does not exist
+ * @return mixed
+ * @throws Exception\ServiceNotCreatedException If factory is not callable
*/
- protected function createFromInvokable($canonicalName, $requestedName)
+ protected function createFromFactory($canonicalName, $requestedName)
{
- $invokable = $this->invokableClasses[$canonicalName];
-
- if (null === $this->creationOptions
- || (is_array($this->creationOptions) && empty($this->creationOptions))
- ) {
- return new $invokable();
- } else {
- if($canonicalName == "dbselect" && is_array($this->creationOptions)) {
- $class = new \ReflectionClass($invokable);
- return $class->newInstanceArgs($this->creationOptions);
- } else {
- return new $invokable($this->creationOptions);
- }
+ $factory = $this->factories[$canonicalName];
+ if (is_string($factory) && class_exists($factory, true)) {
+ $factory = new $factory($this->creationOptions);
+ $this->factories[$canonicalName] = $factory;
}
+ return parent::createFromFactory($canonicalName, $requestedName);
}
/**
View
1 library/Zend/Paginator/ScrollingStylePluginManager.php
@@ -59,4 +59,3 @@ public function validatePlugin($plugin)
));
}
}
-

0 comments on commit 0adecd9

Please sign in to comment.
Something went wrong with that request. Please try again.