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

AJAX e PHP: Aprendendo a base [Parte 1]

AJAX e PHP: Aprendendo a base [Parte 1]

  • August 19, 2008

nota: Este artigo foi publicado pela primeira vez na Quarta Edição da Revista PHP Magazine em março de 2008. Estou agora re-publicando ele aqui em duas partes, 1 e 2 , para melhor visualização

Neste artigo, pretendo apresentar ao Leitor a tecnologia AJAX, resolvendo algumas confusões sobre o que realmente é, e como e onde deve ser usada. Este artigo apresenta um exemplo de como implementar uma solução AJAX sem auxílio de Frameworks. Após palestrar sobre o assunto no 1º PHPDF RoadShow (E no PHP Conference 2007 em São Paulo) decidi por todo material das palestras em um artigo, que foi publicado pela primeira vez na PHP Magazine, e que agora re-publico aqui em meu Blog. Esta primeira parte esta dividida em duas pois descobri que meu WordPress fica louco com artigos grandes. E e breve este artigo terá uma sequencia que entrará no uso de FrameWorks.

Desde que comecei a pesquisar sobre AJAX devo admitir que me apaixonei pela forma que ele permite executar tarefas simples e avançadas de forma amigável, simples e ágil. Desde então, tenho procurado repassar este conteúdo, contribuindo brevemente com o site AJAX Online (www.ajaxonline.com.br ) e publicando diversos artigos em meu blog pessoal.

Read More
OpenAds vira OpenX e fala português

OpenAds vira OpenX e fala português

  • February 22, 2008

Em mais uma reviravolta, a plataforma que começou sua vida como phpAds (1998), virou phpAdsNew, progrediu para OpenAds (passando pelo fork MaxMediaManager) finalmente se formalizou em uma grande plataforma chamada OpenX .

Read More
OpenX 2.5 beta - Primeiras impressões

OpenX 2.5 beta - Primeiras impressões

  • March 28, 2008

Foi anunciado hoje o primeiro beta público do OpenX 2.5, a primeira versão puramente OpenX a ser lançada, digo isso por ser a primeira versão que incorpora as milhares de linhas que forma re-escritas, criando quase que praticamente uma nova aplicação.

Read More