PHP code example of mtymek / blast-input-filter

1. Go to this page and download the library: Download mtymek/blast-input-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mtymek / blast-input-filter example snippets


return [
    'filters' => [
        'factories' => [
            'Foo' => FooFilterFactory::class,
        ],
    ],
    'validators' => [
        'factories' => [
            'Bar' => BarValidatorFactory::class,
        ],
    ],
];
    
$filter = $factory->createInputFilter(
    [
        [
            'name' => 'name',
            'filters' => [
                ['name' => 'Foo'],
            ],
            'validators' => [
                ['name' => 'Bar'],
            ],
        ],        
    ]
);

return $filter;

return [
    'filters' => [
        'factories' => [
            'Foo' => FooFilterFactory::class,
        ],
    ],
    'validators' => [
        'factories' => [
            'Bar' => BarValidatorFactory::class,
        ],
    ],
];

namespace App\InputFilter;

use Zend\InputFilter\InputFilter;

class ContactInputFilter extends InputFilter
{
    public function __construct()
    {
        $this->add(
            [
                'name' => 'name',
                'filters' => [
                    ['name' => 'Foo'],
                ],
                'validators' => [
                    ['name' => 'Bar'],
                ],
            ]
        );

        $this->add(
            [
                'name' => 'content',
                'filters' => [
                    ['name' => 'StringTrim'],
                ],
            ]
        );
    }
}


namespace App\InputFilter;

use Interop\Container\ContainerInterface;
use Zend\InputFilter\Factory;

class ContactInputFilterFactory
{
    public function __invoke(ContainerInterface $container)
    {
        $inputFilter = new ContactForm();
        $inputFilter->setFactory($container->get(Factory::class));
        return $inputFilter;
    }
}


namespace App\InputFilter;

use Interop\Container\ContainerInterface;
use Zend\InputFilter\Factory;

class InputFilterFactory
{
    public function __invoke(ContainerInterface $container, $requestedName)
    {
        $inputFilter = new $requestedName();
        $inputFilter->setFactory($container->get(Factory::class));
        return $inputFilter;
    }
}