DMS\\Filter v2.0

I have completed the release of the DMS\Filter Package, this includes:

  • DMS Filter Library
  • DMS Filter Bundle, that integrates all filtering capabilities in Symfony.

This release includes some new features and a huge overwrite of the filters.

Independent Repositories

The first big change was a proper split of the repositories, before you had the option to go to the DMS repository where all the code would reside together, this gave me a huge overhead in management having to do sub-directory splits all the time and just slowing down releases as a whole.

Now the core library and the Bundle reside in their own repositories and issues are moved there. What does this mean to you? It just means you should report issues and follow releases in these new repositories.

DMS\Filter

Rules rewrite

I’m a big preacher of Object Calisthenics, you may have seen my talk around. And now of the OOP practices described by this is the SOLID acronym. The “S” stands for Single Responsibility, and as it happens my Rules were violating exactly that aspect of it, they were handling both the Annotation aspect of it, and the actual filtering of values. They are now split into two folders Rules, which holds the Annotations and their configuration settings, and Filters holds the classes that actually do filtering, and can even be used apart from the annotations.

This makes little difference to users, unless they were using the classes in a standalone way, but it also allows me more flexibility to provide annotations that work in providing other types of filters, as we will see in the Bundle. This brings a bit more quality to the code, I hope you all like it.

To import annotations, use:

use DMS\\Filter\Rules as Filter;

New Filters: Zend and Callback

I have introduced two new filters into the fold. The Zend Filter allows you to refer to Zend Framework Filters directly form DMS\Filter, this means you can stick to using annotations and a single entry point to get all you filtering news, even if you have need of a Zend Filter. Below is an example of how to use it:

@Filter\Zend('Zend\Filter\HtmlEntities') // options may be passed as the second parameter

The Callback filter supports three types of input:

  • string: name of a method on this same object
  • array: standard PHP call type: {'classname', 'method name'}
  • closure: a closure, which is not supported in case you are using annotations

The callback filter gives you flexibility to create filters that depend on multiple properties of the object.

DMSFilterBundle

New Filter: Service

A new filter is available using the Bundle in Symfony. The service filter allows you to identify a service/method to be called. This gives you the freedom to create your own filters, without having to create all the annotation support it would require. Just use this one annotation and point it to your new service. Below is an example of its usage, beware that you need to import a separate annotation namespace in order to use this filter.

 <?php

namespace App\\Entity;

//Import Annotations use DMS\\Filter\\Rules as Filter;

//Import Symfony Rules use DMS\\Bundle\\FilterBundle\\Rule as SfFilter;

class User { /\*\* \* @Filter\\StripTags() \* @SfFilter\\Service(service="dms.sample", method="filterIt") \* \* @var string \*/ public $name; }

Integration Improvements

The bundle was updated for newer versions of Symfony, as well as implementing proper support for cascade filtering. This means that if you forms use sub-forms which define child entities, these will also be filtered by the automatic form filter. This can also be disabled by setting the cascade_filter to false.

 class TaskType extends AbstractType { // ... public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'cascade\_filter' => false, )); }

// ...

}

Bug fixes

The bundle was not caching its annotation use, we have now fixed that and made use of the same strategy as Symfony uses internally, so you should see improvements if you were looking at this level.

Enjoy!

I hope these new improvements give you a boost in filtering and open up new worlds of amazing possibilities. Not really. But I still hope it helps you. So go, update!

comments powered by Disqus

Related Posts

Um estudo em RSS - Parte 1: XML DOM

Um estudo em RSS - Parte 1: XML DOM

  • July 13, 2006

RSS, hoje me perguntaram “o que é isso?” Eu sei o que é, porém na hora me faltaram palavras para explicar, especialmente palavras que um não-programador consiga absorver de forma a compreender o conceito e seus melhores usos. Portanto com essa série de posts, não sei quantos nem se vou escrever na ordem, mas garanto que vou tentar cobrir tudo.

Read More
The IDEs of March

The IDEs of March

  • March 15, 2012

Last Year, Chris Shiflett started the “Ideas of March” movement, and Jon Tangerine quickly coined the “Ides of March” twist and some people followed him. This year, here we are again and while reading my twitter feed I saw Cal Evans’ post with Jon Tangerine’s line. Of course it was early and I read “IDEs”. Since last year I defended the Ideas of March with why you should blog, and I still believe the reasons stand, this year I’ll just make my own twist and talk about IDEs. Yes, its a shameless sorry attempt at a joke.

Read More
php|tek09 Day #4

php|tek09 Day #4

  • May 25, 2009

And so comes the final day of the 2009 php|tek conference.

Read More