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

Commit

Permalink
Merge branch 'hotfix/4851'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 19, 2013
2 parents b93a62c + 2b8fd51 commit e059c77
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\ValidatorInterface;
use Zend\Validator\ValidatorChain;
use Zend\ServiceManager\ServiceLocatorInterface;

class Factory
{
Expand Down Expand Up @@ -116,7 +117,15 @@ public function clearDefaultValidatorChain()
public function setInputFilterManager(InputFilterPluginManager $inputFilterManager)
{
$this->inputFilterManager = $inputFilterManager;

$serviceLocator = $this->inputFilterManager->getServiceLocator();
if ($serviceLocator && $serviceLocator instanceof ServiceLocatorInterface) {
if ($serviceLocator->has('ValidatorManager')) {
$this->getDefaultValidatorChain()->setPluginManager($serviceLocator->get('ValidatorManager'));
}
if ($serviceLocator->has('FilterManager')) {
$this->getDefaultFilterChain()->setPluginManager($serviceLocator->get('FilterManager'));
}
}
return $this;
}

Expand Down
32 changes: 30 additions & 2 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
use Zend\Validator;
use ZendTest\InputFilter\TestAsset\CustomFactory;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\ServiceManager;

class FactoryTest extends TestCase
{
Expand Down Expand Up @@ -519,7 +520,7 @@ public function testConflictNameWithInputFilterType()

public function testCustomFactoryInCollection()
{
$factory = new CustomFactory();
$factory = new TestAsset\CustomFactory();
$inputFilter = $factory->createInputFilter(array(
'type' => 'collection',
'input_filter' => new InputFilter(),
Expand All @@ -540,4 +541,31 @@ public function testCanSetInputErrorMessage()
));
$this->assertEquals('Custom error message', $input->getErrorMessage());
}

public function testSetInputFilterManagerWithServiceManager()
{
$inputFilterManager = new InputFilterPluginManager;
$serviceManager = new ServiceManager\ServiceManager;
$serviceManager->setService('ValidatorManager', new Validator\ValidatorPluginManager);
$serviceManager->setService('FilterManager', new Filter\FilterPluginManager);
$inputFilterManager->setServiceLocator($serviceManager);
$factory = new Factory();
$factory->setInputFilterManager($inputFilterManager);
$this->assertInstanceOf(
'Zend\Validator\ValidatorPluginManager',
$factory->getDefaultValidatorChain()->getPluginManager()
);
$this->assertInstanceOf(
'Zend\Filter\FilterPluginManager',
$factory->getDefaultFilterChain()->getPluginManager()
);
}

public function testSetInputFilterManagerWithoutServiceManager()
{
$inputFilterManager = new InputFilterPluginManager();
$factory = new Factory();
$factory->setInputFilterManager($inputFilterManager);
$this->assertSame($inputFilterManager, $factory->getInputFilterManager());
}
}

0 comments on commit e059c77

Please sign in to comment.