Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Last active January 3, 2016 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thinkscape/8418700 to your computer and use it in GitHub Desktop.
Save Thinkscape/8418700 to your computer and use it in GitHub Desktop.
<?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