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

Commit 5da0a82

Browse files
committed
Merge branch 'feature/3' into develop
Close #3
2 parents b658eee + 5eed0ed commit 5da0a82

5 files changed

+75
-1
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file, in reverse
66

77
### Added
88

9-
- Nothing.
9+
- [#3](https://github.com/zendframework/zend-inputfilter/pull/3) updates the
10+
`InputFilterAbstractServiceFactory` to inject the created input filter factory
11+
with the `InputFilterManager` service, ensuring that the generated factory can
12+
pull named input filters and inputs from the container as needed.
1013

1114
### Deprecated
1215

src/InputFilterAbstractServiceFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ protected function getInputFilterFactory(ServiceLocatorInterface $services)
118118
->getDefaultValidatorChain()
119119
->setPluginManager($this->getValidatorPluginManager($services));
120120

121+
$this->factory->setInputFilterManager($services->get('InputFilterManager'));
122+
121123
return $this->factory;
122124
}
123125

test/InputFilterAbstractServiceFactoryTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1313
use PHPUnit_Framework_TestCase as TestCase;
1414
use Zend\Filter\FilterPluginManager;
15+
use Zend\InputFilter\InputFilter;
1516
use Zend\InputFilter\InputFilterAbstractServiceFactory;
1617
use Zend\InputFilter\InputFilterInterface;
1718
use Zend\InputFilter\InputFilterPluginManager;
@@ -246,4 +247,29 @@ protected function getCompatContainer()
246247
return $this->filters;
247248
}
248249
}
250+
251+
252+
/**
253+
* @depends testCreatesInputFilterInstance
254+
*/
255+
public function testInjectsInputFilterManagerFromServiceManager()
256+
{
257+
$this->services->setService('config', [
258+
'input_filter_specs' => [
259+
'filter' => [],
260+
],
261+
]);
262+
$this->filters->addAbstractFactory('ZendTest\InputFilter\TestAsset\FooAbstractFactory');
263+
264+
/**
265+
* @type InputFilter $filter
266+
*/
267+
$filter = $this->factory->createServiceWithName($this->filters, 'filter', 'filter');
268+
269+
$inputFilterManager = $filter->getFactory()->getInputFilterManager();
270+
271+
$this->assertInstanceOf('Zend\InputFilter\InputFilterPluginManager', $inputFilterManager);
272+
273+
$this->assertInstanceOf('ZendTest\InputFilter\TestAsset\Foo', $inputFilterManager->get('foo'));
274+
}
249275
}

test/TestAsset/Foo.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\InputFilter\TestAsset;
11+
12+
use Zend\InputFilter\BaseInputFilter;
13+
14+
class Foo extends BaseInputFilter
15+
{
16+
}

test/TestAsset/FooAbstractFactory.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\InputFilter\TestAsset;
11+
12+
use Zend\ServiceManager\AbstractFactoryInterface;
13+
use Zend\ServiceManager\ServiceLocatorInterface;
14+
15+
class FooAbstractFactory implements AbstractFactoryInterface
16+
{
17+
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
18+
{
19+
if ($name == 'foo') {
20+
return true;
21+
}
22+
}
23+
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
24+
{
25+
return new Foo;
26+
}
27+
}

0 commit comments

Comments
 (0)