DMS\Filter Library 1.0.1 and Bundle
The past weeks I finally had some time to invest in the DMS library again, so i got busy with a few things. I also had to fix a big problem which had gone unnoticed to me, so i have to thank Mr. Guilherme Blanco for pointing it out.
Sadly this means a BC break, so please follow and make adjustments.
The BC break: ->filter() becomes ->filterEntity()
The reasoning here is simple, PHP still supports legacy from PHP4 meaning a function with the same name as the class is understood as a constructor. This generates a few nasty notices, and it made enough sense to rename the function, making it clear like the other ones.
The DMSFilterBundle
Along with this i had time to work on building a Bundle so you can plug filtering into Symfony 2 just as you would with validation.
Composer support
This bundle is also available on Packagist, making it easy to install, i'll also add the DMS and Filter library as standalones to this soon.
Tags
I finally tagged the releases as 1.0, or rather 1.0.1 as i quickly found a few fixes to put in.
The rest remains, here are the links:
DMS Library: github
DMS Filter Library (sub-tree split): github
DMS Filter Bundle (sub-tree split): github | packagist/composer | knpbundles page (please recommend it if you like it)
PHP Benelux 2012 – Learning lessons
After hearing about how great PHP Benelux Conferences were I finally made it over to Belgium to check it out, and i was impressed. To catch you up on the new, I moved to Amsterdam last december and thus had the chance of attending the conference which is now 2 hours away on a train ride.
I could not expect less of a wonderful conference when names like Michelangelo van Dam are involved and this was no exception. Its a community conference, planned and organized by community leaders and for community members, this is what makes it so amazing that even without a big name behind it this conference can put up quite a show and bring so many sponsors. As I sat there watching the closing remarks I realized other User Groups and conferences have lots of lessons to pickup from this conference. Let me name a few:
1. Value your sponsors. This was very well executed, during the whole event the sponsors had their logos all over the place and the ones who were present had plenty one on one time with conference attendees. Finally during closing remarks each one was mentioned and with a touch of genius their contributions were described, talk about being thankful.
2. Value your speakers. Who would not want to be a speaker at a conference where you get free belgian beer and chocolates at the end? I know i would, and i'm not even a beer drinker. The amount of care put into the speakers is legendary, pickups, great hotel and i can only imagine what else I did not see myself as a non-speaker.
3. Value your attendees. This should be easy, but lots of conferences fail at it. Good sessions, good venue, good food and infrastructure, just make your client feel confortable. Don't make him want, make everything available to him at the venue and keep him around for more networking and fun.
4. Awesome socials are awesome. The social events around a conference are the crowning jewel to the experience, it allows for much more networking and just plain fun and bonding. This is great for speakers and attendees alike, and is usually the moment where great projects take shape. There is a lot to learn from a chat with Ian Barber about public speaking, he even put it in writing. And there was so much more.
5. Make your attendees pay. Yeah, I said pay. Many conferences think that being "open source" means having a free conference, I say "ppfffff". Charge a reasonable "I'm a beginner developer with low income"-price and put up a great conference using that money, and people will pay. If they do not pay their employers will, if neither of them does, the problem is bigger. Surely the people who will be leaving the conference better then they came in will be willing to pay. This also adds value to the conference, makes it an investment.
6. Value the organizers and your volunteers. There was no single-man effort in the conference, they (from what i saw) worked together like a very well oiled machine. Many times did i see all organizers united discussing something and no man was left trying to solve everything alone. Expand your group, get more people, get volunteer and be sure to thank them, give them their "dues", they will give you their all.
7. Have Fun! Events are always stressful, but you would never guess this from seeing the PHP Benelux crew at work. They just had fun with it, enjoyed, worked, solved solvable problems and apologized for unsolvable ones, what more do we need?
There are probably more lessons to be learnt here, it was a very well executed event, with great speakers, great guests. Coming from Brazil to such a rich network of PHP events is very exciting for me, I love events and now i have multiple large events all around me.
In Belgium I got to see great friends, make new ones, ans most of all realize that it will not be a year before I see them again (yay!). I also picked up quite a few topics to research more and study, as well as being inspired to kickoff new projects and old ideas, the keynotes really did an awesome job to get us inspired.
You can be sure to find me around PHP Benelux 2013, I will be putting out my best to be either a speaker or an attendee, but I'll be there for sure. Congratulations PHP Benelux Crew, it was a wonderful show and a great experience.
Back to the Old Continent
"Your life begins where your comfort zone ends" (@elizabethN's mother)
My time at SWATends just shy of four years, and I can truly say it has been the biggest, most wonderful and most amazing professional experience of my life. I joined swat as a small user group manager and I am leaving as an international speaker, OSS contributor and manager of a awesome user group.Time has knocked on my door, I'm no longer 20 and time is not waiting around for me, so its time to kick my life's plan back into gear and proceed to the next steps. Working for SWAT with such incredible and inspiring people, enabled me to reach a very comfortable point in my career, to expand my network over the borders of Brazil, getting to know so many awesome people, literally from the US all the way around to the Philippines.
I was given a chance to challenge myself and follow in the lines of SWAT's CEO, Jacques van Niekerk, an amazing leader who inspired me to always express myself when my area of expertise was the topic. And many other amazing co-workers, experienced in so many fields. My direct team in the Brazil office with experts minds in PHP, Architecture and UX kept me on my toes and I'm very grateful for working with all these professionals.But @ElizabethN's mom had it right from the beginning and I have decided its time to seek new challenges, become a small fish in a bigger pond once again and learn from so many other great minds out there. Brazil has a huge and wonderful PHP community, which I watched and helped grow over these years, but so much is happening outside and I want to immerse myself in these "new waters" to take that next professional step.
As of the end of this year, I will be taking my place at WEBclusive in Amsterdam, The Netherlands. This is a huge and exciting step for me and my wife, but one that comes after much pondering and at a very good time, moving to outside of Brazil was a old plan of ours and Europe is the right place at the right time. Both a culturally amazing region and also a florishing PHP community with so many conferences and the epicenter of the latest developments in frameworks and the language.
I hope to be able to reach out and talk to so many of my European development buddies and hang out much more often with them and my US friends as well, for sure i will be bothering names like @skoop, @dragonbe, @lornajane, @derickr, @akrabat and @davidcoallier much more now, and that's just to name a few.
Thank you SWAT team for these awesome years, and thank you to the Brazilian PHP Community, we have grown so much over the last years, I'm very proud of the work done by so many people, I can only hope this work keeps going and that I can help as much as possible from the outside.
Filtering objects using annotations
Filtering with Annotations
PHP does not have native Annotations support, however many projects have been using doc blocks to add value and semantics to code, like PHPUnit, Doctrine and Symfony. The Doctrine did a really good job in making available a Annotation parser kit, which allows you to bring the power of annotations into you own project. This opens up a few possibilities.
Input Validation and Filtering
Rule #1 of the developer is “Filter input, escape output”. To me treating input has two distinct steps which are very important: Filtering and Validation. Symfony 2 has come out with a very cool Validation library which makes validation possible using annotations. It relies on a set of constraints which can be attached to properties of your object, allowing you to simply pass your objects to a validation service and it will do the rest for you. Like this:
<?php
// src/Acme/BlogBundle/Entity/Author.php
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\NotBlank()
*/
public $name;
}
?>
<?php
$author = new Author();
$validator = $this->get('validator');
$errorList = $validator->validate($author);
?>
This is a very nice and clean way of handling validation, it allows all rules to be centered on the entities, making maintenance easy. A nice complement is that constraints can be added to the class so they use more then one variable, as well as allowing you to create your own contraints.
However the library lacks one thing, which Zend_Filter_Input does very well, Filtering. Most data needs to be filtered before going in for validation, and even of Symfony2 offers a Data Transformer, that is not quite what is needed here, so I came out with the only other solution, build one myself.
DMS\Filter
I wanted a library with all the power of the filters out there and the advantage of using annotations to provide its interface. So i set about studying the annotations implementation in doctrine and the Symfony2 Validator and came up with my own Filter library. It was designed to be simple and to be used alongside doctrine and symfony validator, so it depends on Doctrine Common.
Its composed of a filter service which is capable of reading “filter rules” from object properties and iterate over them, even private and protected ones, filtering the values. It works based on the object instance which is not cloned, so the object is altered and does not need to be returned nd re-assigned.
To add rules to you properties, just declare the namespace use and go for it, like this:
<?php
namespace App\Entity;
//Import Annotations
use DMS\Filter\Rules as Filter;
class User
{
/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public $name;
/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public $email;
}
?>
To filter your instance, just do it like this:
<?php
//Get Doctrine Reader
$reader = new Annotations\AnnotationReader();
$reader->setEnableParsePhpImports(true);
//Load AnnotationLoader
$loader = new Mapping\Loader\AnnotationLoader($reader);
$this->loader = $loader;
//Get a MetadataFactory
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
//Get a Filter
$filter = new DMS\Filter\Filter($metadataFactory);
//Get your Entity
$user = new App\Entity\User();
$user->name = "My <b>name</b>";
$user->email = " email@mail.com";
//Filter you entity
$filter->filter($user);
echo $user->name; //"My name"
echo $user->email; //"email@mail.com"
?>
You can also recycle an AnnotationReader already in use by Symfony Validator for example. The AnnotationReader is currently changing in Doctrine Common, but DMS\Filter tries to auto-configure its namespace, I will be keeping an eye on this in the future.
The project is available in two forms, inside the DMS library on github, or as a standalone component, also on github (sub tree split FTW!). It has a limited number of filters, but you can develop your own filters to use or just open up an issue and i'll create them.
Hope the library is useful and you enjoy it.
PHP Development in the Cloud by Ivo Jansch and Vito Chin
Cloud computing is finally reaching a point of maturity and leaving its early “hype” years behind. Ivo and Vito do a very good job of bringing the topic into a PHP developer’s world in a very concise and objective manner, without leaving important platforms and concepts behind.
From the top the book sets down the glossary and explains very clearly what Cloud computing is and where it stands, which is very important if you are to decide wether its the solution for you or not. It also brings the concept into technical view reviewing the differences between a regular hosting environment and a elastic cloud structure. This is very important to architects building new applications that mean to take full advantage of the cloud. Finally the book overviews a few examples and most importantly a few providers and solutions, such as Amazon, Windows Azure and Google App Engine.
The book was a very pleasant read, not thick and not too thin. It helped me greatly as I prepared to give a presentation on Cloud Computing, allowing me to see different points of view as well as compare other technologies i had not had time or chance to try. I recommend this for any application architect who is thinking if the cloud is the right solution, but even if its not on your mind yet. Its very important to know where the cloud fits in so that when given a choice you will know the cloud is an option to be considered.
Title: PHP Development in the Cloud - a php|architect Guide
By: Ivo Jansch and Vito Chin
Publisher: Blue Parabola
Pages: 172
ISBN: 9780981034522
Buy it: At php|architect

