2017 © Pedro Peláez
 

library blast-input-filter

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

image

mtymek/blast-input-filter

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  • Wednesday, November 15, 2017
  • by mtymek
  • Repository
  • 1 Watchers
  • 3 Stars
  • 1,612 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 36 % Grown

The README.md

Blast\InputFilter

Build Status, (*1)

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Zend Expressive applications., (*2)

This package provides factories that allow to define custom filters and validators using configuration:, (*3)

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

Later on they can be used directly when building an input filter:, (*4)

$filter = $factory->createInputFilter(
    [
        [
            'name' => 'name',
            'filters' => [
                ['name' => 'Foo'],
            ],
            'validators' => [
                ['name' => 'Bar'],
            ],
        ],        
    ]
);

return $filter;

Installation

This package supports installation with composer:, (*5)

$ composer require mtymek/blast-input-filter

Usage

Define your custom filters and validators

blast-inputfilter allows to set-up respective plugin managers using filters and validators keys:, (*6)

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

This works exaclty like when using zend-mvc, only without performance penalty of ZF's module manager., (*7)

Create input filter

There are couple of ways of creating input filter and injecting it with elements. One of them is to use __construct method to create all inputs and specify validators:, (*8)

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'],
                ],
            ]
        );
    }
}

Create factory for your filter

In order for custom filters and validators to work, you need to pull Zend\InputFilter\Factory from service container and inject it into your input filter:, (*9)


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; } }

Please note that you can use more generic factory to instantiate more input filters:, (*10)


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; } }

The Versions

15/11 2017

dev-master

9999999-dev

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  Sources   Download

BSD-2-Clause 2-Clause BSD

The Requires

 

The Development Requires

15/05 2017

1.0.0

1.0.0.0

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

15/05 2017

dev-v_1

dev-v_1

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

17/05 2016

0.1.1

0.1.1.0

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires

14/05 2016

0.1.0

0.1.0.0

Configuration-based setup of zend-validator, zend-filter and zend-inputfilter for Expressive applications.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires