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

Change to InputFilterFactory and CollectionInputFilter to support nested input-filter config #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/InputFilterAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ protected function getInputFilterFactory(ServiceLocatorInterface $services)
->getDefaultValidatorChain()
->setPluginManager($this->getValidatorPluginManager($services));

$this->factory->setInputFilterManager($services->get('InputFilterManager'));

return $this->factory;
}

Expand Down
12 changes: 10 additions & 2 deletions src/InputFilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ public function populateFactory($inputFilter)
$factory->setInputFilterManager($this);

if ($this->serviceLocator instanceof ServiceLocatorInterface) {
$factory->getDefaultFilterChain()->setPluginManager($this->serviceLocator->get('FilterManager'));
$factory->getDefaultValidatorChain()->setPluginManager($this->serviceLocator->get('ValidatorManager'));
if ($this->serviceLocator->has('FilterManager')) {
$factory->getDefaultFilterChain()->setPluginManager(
$this->serviceLocator->get('FilterManager')
);
}
if ($this->serviceLocator->has('ValidatorManager')) {
$factory->getDefaultValidatorChain()->setPluginManager(
$this->serviceLocator->get('ValidatorManager')
);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/InputFilterAbstractServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Filter\FilterPluginManager;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\ServiceManager\ServiceManager;
use Zend\Validator\ValidatorPluginManager;
Expand Down Expand Up @@ -153,4 +154,30 @@ public function testRetrieveInputFilterFromInputFilterPluginManager()
$inputFilter = $this->services->get('InputFilterManager')->get('foobar');
$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);
}


/**
* @depends testCreatesInputFilterInstance
*/
public function testInjectsInputFilterManagerFromServiceManager()
{
$this->services->setService('Config', array(
'input_filter_specs' => array(
'filter' => array(),
),
));
$this->filters->addAbstractFactory('ZendTest\InputFilter\TestAsset\FooAbstractFactory');

/**
* @type InputFilter $filter
*/
$filter = $this->factory->createServiceWithName($this->filters, 'filter', 'filter');

$inputFilterManager = $filter->getFactory()->getInputFilterManager();

$this->assertInstanceOf('Zend\InputFilter\InputFilterPluginManager', $inputFilterManager);

$this->assertInstanceOf('ZendTest\InputFilter\TestAsset\Foo', $inputFilterManager->get('foo'));
}

}
16 changes: 16 additions & 0 deletions test/TestAsset/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\InputFilter\TestAsset;

use Zend\InputFilter\BaseInputFilter;

class Foo extends BaseInputFilter
{
}
27 changes: 27 additions & 0 deletions test/TestAsset/FooAbstractFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\InputFilter\TestAsset;

use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class FooAbstractFactory implements AbstractFactoryInterface
{
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
if ($name == 'foo') {
return true;
}
}
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return new Foo;
}
}