Skip to content

Instantly share code, notes, and snippets.



Created May 21, 2014
What would you like to do?
class UserInputFilterFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $service)
$factory = // Get from SL;
$inputCollection = new InputCollection('user');
$input = $factory->createInput([
'name' => 'foo',
'validators' => []

This comment has been minimized.

Copy link

@texdc texdc commented May 27, 2014

First of all, let me reiterate my hatred for the term InputFilter. :)

Any component that allows adding other components should have a factory injected in the constructor.

namespace Zend\Input;

use Zend\Stdlib\PriorityQueue;

class Collection implements InputInterface
    private $factory;

    private $name;

    private $inputs;

    public function __construct($name, FactoryInterface $factory, array $inputSpecs = [])
        $this->name    = trim($name);
        $this->factory = $factory;
        $this->inputs  = new PriorityQueue;

    public function addInput(InputInterface $input, $priority = 0)
        $this->inputs->append($input, $priority);

    public function addInputSpec(array $spec)
        $priority = isset($spec['priority']) ? $spec['priority'] : 0;
        $this->addInput($this->factory->build($spec), $priority);

    public function addInputSpecs(array $specs)
        foreach ($specs as $spec) {


namespace My\User\Serivce;

use Zend\Input\Collection;
use Zend\Service\FactoryInterface;
use Zend\Service\LocatorInterface;

class InputCollectionFactory implements FactoryInterface
    public function createService(LocatorInterface $locator)
        $factory = $locator->get('Zend\Input\FactoryInterface');
        $specs   = $locator->get('my.user.input');
        return new Collection('user', $factory, $specs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.