Last active
January 3, 2016 05:49
-
-
Save Thinkscape/8418700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\App; | |
use Zend\Filter\FilterChain; | |
use Zend\InputFilter\Factory; | |
use Zend\ServiceManager\FactoryInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
use Zend\Validator\ValidatorChain; | |
/** | |
* This allows for defining new userland input filters via Module::getInputFilterConfig() or config files. | |
* | |
* In your module config add the following: | |
* [ | |
* // define your custom filters here | |
* 'input_filter' => [ | |
* 'somefilter' => 'My\App\Filter\SomeFilter' | |
* ], | |
* | |
* // Make sure to register the factory in your config:: | |
* 'service_manager' => [ | |
* 'factories' = [ | |
* 'Zend\InputFilter\Factory' => 'My\App\InputFilterFactoryFactory', | |
* ] | |
* ] | |
* ] | |
* | |
* Now you can use the factory in your code: | |
* $inputFilter = new InputFilter(); | |
* $inputFilter->setFactory($serviceLocator->get('Zend\InputFilter\Factory')); | |
* $inputFilter->add('name', 'stringtrim'); | |
* | |
*/ | |
class InputFilterFactoryFactory implements FactoryInterface | |
{ | |
public function createService(ServiceLocatorInterface $serviceLocator, $canonicalName = null, $requestedName = null) | |
{ | |
$factory = new Factory(); | |
$factory->setDefaultFilterChain(new FilterChain()); | |
$factory->setDefaultValidatorChain(new ValidatorChain()); | |
$factory->setInputFilterManager($serviceLocator->get('InputFilterManager')); | |
return $factory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment