Skip to content
Symfony filtering bundle
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Annotation Update code style Jan 31, 2019
DependencyInjection Fix Tree builder deprecation Jan 31, 2019
EventListener Update code style Jan 31, 2019
Resources/config Allow Symfony 4 Dec 8, 2017
Service Update code style Jan 31, 2019
Tests Update code style Jan 31, 2019
.gitignore Update CS and packages. Sep 22, 2017
.php_cs Update CS settings Nov 13, 2017
.scrutinizer.yml init Mar 16, 2016
.travis.yml Fix count bug Dec 21, 2017
Bukashk0zzzFilterBundle.php Update code style Jan 31, 2019
LICENSE init Mar 16, 2016 Update Jan 31, 2019
composer.json Update dependencies Dec 8, 2017
phpunit.xml.dist Fix tests php strict types Sep 22, 2017
ruleset.xml Update code style Jan 31, 2019

Symfony Filter Bundle

Build Status Code Coverage Scrutinizer Code Quality License Latest Stable Version Total Downloads



This bundle add a service that can be used to filter object values based on annotations. ZendFilters used for filtering. Also bundle can filter your forms if it finds a annotated entity attached. If auto_filter_forms enabled entities will be filtered before they are validated. Zend filters doc

Installation Symfony Flex

composer config extra.symfony.allow-contrib true
composer require bukashk0zzz/filter-bundle

Installation without Symfony Flex

composer require bukashk0zzz/filter-bundle

Add the bundle to app/AppKernel.php

$bundles = array(
	// ... other bundles
	new Bukashk0zzz\FilterBundle\Bukashk0zzzFilterBundle(),


Add this to your config.yml:

    # Enable if you need auto filtering form data before constraint(Validation) check
    auto_filter_forms: false


Bundle provides one annotation which allow filter fields in your entities.

Add the next class to the use section of your entity class.

use Bukashk0zzz\FilterBundle\Annotation\FilterAnnotation as Filter;

Annotation @Filter has one required option filter which value should be name of Zend filter class. It can be set like this @Filter("StringTrim") or @Filter(filter="AppBundle\Filter\MyCustomFilter").

AppBundle\Filter\MyCustomFilter - in this example, must be class that extends \Zend\Filter\AbstractFilter

Also there is one not required option options - it must be array type and will pass to Zend filter using setOptions method from zend filter.

Example entity

namespace AppBundle\Entity;

use Bukashk0zzz\FilterBundle\Annotation\FilterAnnotation as Filter;

 * User Entity
class User
     * @Filter("StripTags", options={"allowTags": "br"})
     * @Filter("StringTrim")
     * @Filter("StripNewlines")
     * @var string
    protected $name;

     * @Filter("StripTags")
     * @Filter("StringTrim")
     * @Filter("AppBundle\Filter\MyCustomFilter")
     * @var string
    protected $about;

Using filter service

Use the bukashk0zzz_filter.filter service along with annotations in the Entity to filter data.

public function indexAction()

    $entity = new \Acme\DemoBundle\Entity\SampleEntity();
    $entity->name = "My <b>name</b>";
    $entity->email = "";

    $filterService = $this->get('bukashk0zzz_filter.filter');

    return ['entity' => $entity];

Copyright / License


You can’t perform that action at this time.