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

4ª Edição da PHP Magazine, e artigo sobre AJAX

4ª Edição da PHP Magazine, e artigo sobre AJAX

  • March 10, 2008

Finalmente saiu a 4ª edição da PHP Magazine, prometida para agosto de 2007.

Read More
Analisando a PHP Conference Brasil 2008 e slides da palestra

Analisando a PHP Conference Brasil 2008 e slides da palestra

  • December 3, 2008

Mais um ano e mais uma PHPConf , este ano uma nuvem de discussões e #mimimi rodeou a realização de todos eventos de PHP, mas acredito que o resultado final tenha sido positivo o bastante para deixar isto para trás.

Read More
Iterating over life with SPL Iterators I: Directories

Iterating over life with SPL Iterators I: Directories

  • October 8, 2009

In the past i have already talked about SPL and how it makes PHP Developers’ life a breeze, since then i have felt a lack of SPL recipes around the web, if you are getting into SPL now, using some of the available classes can be a real mystery, so I decided to add more posts to google’s list of SPL articles.

Read More