2017 © Pedro Peláez
 

library input-filter

Input Filter module for zend framework 3

image

vim/input-filter

Input Filter module for zend framework 3

  • Friday, January 19, 2018
  • by vanvas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

input-filter

Module for Zend Framework 3., (*1)

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org., (*2)

composer require vim/input-filter

Register Vim\InputFilter in config/modules.config.php:, (*3)

<?php
return [
    'Vim\InputFilter',
];

Example

  1. Create input filter service
<?php
namespace Application\InputFilterBuilder;

use Vim\InputFilter\InputFilter\InputFilterBuilderAwareInterface;

class ArticleInputFilterBuilder implements InputFilterBuilderAwareInterface
{

    /**
     * [name => [required => {boolean}, validators => {array}, filters => {array}]]
     * @return array
     */
    public function getConfig(): array
    {
        return [
            'alias' => [
                'required' => true,
                'validators' => [],
                'filters' => [
                    'StripTags',
                    'StringTrim' => [],
                ],
            ],
            'title' => [
                'required' => true,
            ],
        ];
    }
}
  1. Register input filter service in service manager
<?php
return [
    'service_manager' => [
        'factories' => [
            \Application\InputFilterBuilder\ArticleInputFilterBuilder::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
        ],
    ],
];
  1. Get input filter service from abstract factory
<?php
/** @var \Vim\InputFilter\Service\InputFilterBuilderService $inputFilterBuilder */
$inputFilterBuilder = $service = $container->get(\Vim\InputFilter\Constant\AbstractFactoryPrefixConstant::INPUT_FILTER_BUILDER_PREFIX.\Application\InputFilterBuilder\ArticleInputFilterBuilder::class);
$inputFilter = $inputFilterBuilder->create();
  1. Filter and validate data
<?php
$inputFilter->setData(
    [
        'alias' => 'some_alias',
        'title' => 'some title',
    ]
);
var_dump($inputFilter->isValid());

If application is multilanguage:

composer require doctrine/doctrine-orm-module
composer require vim/language
composer require vim/translatable
  1. Create input filter service
<?php
namespace Application\InputFilterBuilder;

use Vim\InputFilter\InputFilter\InputFilterBuilderAwareInterface;
use Vim\InputFilter\InputFilter\InputFilterBuilderTranslatableAwareInterface;

class ArticleInputFilterBuilder implements InputFilterBuilderAwareInterface, InputFilterBuilderTranslatableAwareInterface
{

    /**
     * [name => [required => {boolean}, validators => {array}, filters => {array}]]
     * @return array
     */
    public function getConfig(): array
    {
        return [
            'alias' => [
                'required' => true,
                'validators' => [],
                'filters' => [
                    'StripTags',
                    'StringTrim' => [],
                ],
            ],
            'title' => [
                'required' => true,
            ],
        ];
    }

    /**
     * @return array
     */
    public function getTranslatableFieldList(): array
    {
        return ['title'];
    }
}
  1. Register input filter service in service manager, (*4)

  2. Get input filter service from abstract factory, (*5)

  3. Filter and validate data, (*6)

<?php
$inputFilter->setData(
    [
        'alias' => 'some_alias',
        'translation' => [
            'en' => [
                'title' => 'some title',
            ],
        ],
    ]
);
var_dump($inputFilter->isValid());

The Versions

19/01 2018

dev-master

9999999-dev https://github.com/vanvas/input-filter.git

Input Filter module for zend framework 3

  Sources   Download

The Requires

 

php zend framework multilanguage zf2 module input filter zf3 module input filter builder

19/01 2018

1.0.0

1.0.0.0 https://github.com/vanvas/input-filter.git

Input Filter module for zend framework 3

  Sources   Download

The Requires

 

php zend framework multilanguage zf2 module input filter zf3 module input filter builder