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.
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
The ideas of March
This year my New Year's resolution was to "write more" just as plain as that, blog more, write articles, maybe even a book can fit in there. Now it seems that resolution is in sync with the rest of the PHP Community and Chris Shifflet has once again caused ripples to roam the community with his Ideas of March initiative.
This blog for me is a crucial part of my professional self, hence the determination to revive the blog and the website in this year. "Why?", you may ask. Well its very simple, blogs can withstand the test of time, they do not come and go or just vanish from the internet, like tweets do. Tweets are fine to get a message started, but they suck for getting into real discussions and for actual knowledge growth, it works, but its shallow at best, the 140 chars limit will do that to you. But on the blog your limits are gone, google will keep that blogpost relevant for years to come, my first post on the Google Maps API is living proof, still the most visited article here after 4 years.
In a world where saying you are good at something is falling into misuse and disbelief, an active blog can assert to your skills and your career work, even your passions and your motivation. It can do all of that much better then a CV can, it can also provide you with professional projection, throwing your name around until it hits your potential future employer.
Its also all about knowledge. A blog can spread your knowledge, it can bring you knowledge, in the format of comments, discussions and feedback (as Sean Coates put it), and it can also help developers who, like me, suffer of cronic forgetfulness. Seriously, its a bitter-sweet feeling to search google for a topic and end up reading your own blogpost from years past.
So why should you blog, not just tweet? in summary:
- Timeless: Blogposts don't expire
- Professional Projection: Get your name out there, show what you do well
- Professional Growth: Learn, expand, teach and get feedback
- Help yourself: store your knowledge in a searchable place
- Details: Blogs allow you to do in-depth articles and discussions
- Get evaluation going: start discussions, propose changes, make something happen
So i'll take the pledge proposed by Chris (especially since i have already commited to it) and blog more actively this year. You can also check me up on php|arch every now and then (in the future) and in brazil in our PHP Review magazine. Want to watch twitter? please do, i'll always link off from there to these posts.
So don't let this stop here, take the "Ideas of March" challenge yourself.
Managing Test Users in Facebook
Recently Facebook implemented a new and more secure way of creating test users for your applications using the new Graph API. This new resource creates test users per application, allowing the developers of these apps to login as these users and test out their app’s functionality without using their own accounts and throwing test information into their live activity feed, this makes it very easy and clean to test new applications.
Its possible to create up to 100 test users per app, creation allows you to choose whether the user already should have the application installed and which permissions you want them to have, using API calls like:
POST /app_id/accounts/test-users?installed=true&permissions=read_stream
You can also remove users, list all of your app’s test users and even create friend connections between them using the API. This really is a great resource, but using an API to get this information all the time is cumbersome and might take time away from your time to develop the application itself.
This is where the Test User Manager comes in.
Having ran into this exact issue when developing for Facebook, I wished i could have a “phpMyAdmin”-like application to handle these requests for me and just give me a simple interface to work with. That’s when the idea was born an i decided to use the idea and opportunity to simplify my life and also learn/research a few other libraries and such.
I decided to create a very simple app, without a large MVC framework, just a bunch of actions. I also took the opportunity to use a simple template engine to see how it behaves, so i chose Twig for this. Since i did not have the comfort of large MVC framework to handle my requests, i also decided to look at funkatron’s Inspekt library to handle input security. Since i did not want to go through some troubles I also imported a limited set of tools from Zend Framework to handle autoloading and smaller tasks. Also having not worked with front-end too much in a while I took hold of jQuery and a few plugins to see what they could do.
All in all i had a very simple but effective app. Right now (version 0.9) it does the basics, add, lists, deletes and creates relationships between Test Users. But it handles exactly the most boring and annoying tasks. Let me show you a bit:
Listing/Managing Users
The user list will show you all of your test users, their IDs, name and permissions. With the command icons you can see the access_token, login on Facebook as the user, delete him or add new friends. Since this is a API heavy process to get all information loading is done in parallel using ajax.
Creating a User
The for to add new users is straight forward, you can add permissions and decide if the app will be installed or not for the user.
Viewing and Creating relationships
Clicking on the “add friend” icon you can view a list of existing relationships and choose a new user to associate with this user.
All the source code for this application is on GitHub, feel free to open feature requests and bug reports and of course pull requests at will. I hope this app can help you as a Facebook developer and make everyday life easier.




