CSV Response in Symfony controller action

May 21st, 2014


Add a comment »

Reddit picks

May 13th, 2014

I want to start sharing some Reddit posts I found interesting or posts I’ve created myself. So for my first series here they are:

Wrapper methods: are they good or not? Here you can find some interesting insights on wrapper methods subject I wrote last time.

BDD or TDD? I recently asked what path should I take when testing my application and I got some good comments on the subject.

Container parameters or configuration values? On this post I asked why configuration values are better then service parameters in Symfony2 and I got a response from the author of the presentation I was referring.

Method chaining: yes or no? Although this is not one of my posts, the subject is quite interesting. I always thought  that returning $this from a method is a good idea, but apparently is not. Check the comments to read why.

Add a comment »

Tools for coding standards

May 8th, 2014

As a professional developer I try as much as possible to create a discipline for clean projects. And one of the measure I take is to respect the coding standards specification. It’s not hard and it doesn’t take much time especially if you start respecting the standards from the beginning of your project.

Here is a list with the coding standards I use. And here are the tools I use every time:

Add a comment »

Using the php \Soap client with a .p12 file

May 7th, 2014

1. Convert the certificate from .p12 to .pem

2. Create the SOAP client and check the available functions:

Add a comment »

Wrapper methods: are they good or not?

May 3rd, 2014

Last week I was doing some pairing programming with a colleague of mine, and we were designing an API client class and at one point inside a method I had this piece of code:

And I suggested we should modify these lines like this:

“Why would you that? It would be only a wrapper method for the container getParameterMethod()” my colleague asked me.

So the question is: does it worth to create a wrapper method for only one line of code?

I think it depends on how you choose to structure your code, but I usually do for these reasons:

1. Readability

getCompanyAddress() it’s way more readable than getContainer()->getParameter(‘client.subscribe.deliveryAddress’). Yes, for you it might be the same, but think about future programmers who will work on your code. When we are reading code lines, we are doing this with the sole purpose of understanding what it does. A getCompanyAddress will give the exact answer without reading and trying to understand what a bunch of lines do.

2. Avoiding comments

I think if you need comments above a line of code, then your code is not self-explanatory, and it’s often a hint that you should create a new method with a good naming. I like to think my wrapper methods like “working comments”, because they are like a comment which is executing and does stuff.

So as a rule of thumb when I feel the need to comment code I ask myself if method with a descriptive name should be added instead.

3. Better debugging and fixing code

I think for a new programmer it will be easier for him to find where the problem is when a bug is occurring. And if he needs to fix it then he will be sure that if he will fix that method the code is working.

What do you think? Are wrapper methods a waste of time and space or do you make use of them?


Best practices in Symfony2

May 3rd, 2014

Add a comment »

Mailchimp is using PHP

January 24th, 2014

“We’ve built a framework for developing applications in PHP specifically designed to allow for fast innovation in the high-load, high-performance environment we live in every day while still keeping the API extremely simple to deal with. This isn’t your grandfather’s PHP, or even your slightly older brother’s. I can say without doubt that it is the most sophisticated framework for this environment that I’ve heard of except for perhaps what Facebook uses. Our architecture is heavily sharded, fast, and scalable to handle the absurd amount of growth we’ve had in the last few years.

We use this architecture to process well over thirty million emails sent by tens of thousands of users every day, generating tens of millions of bounces, opens, clicks, and unsubscribes that all need to be handled in near-real time. We further process millions of API requests and millions of subscribes and confirmations every day. All told, we handle well over 500 million dynamic page views a month. Our backend systems run millions of jobs every day, calculating statistics, querying geographic data, and scanning everything for bad behavior and abuse.”

Read more here: Ewww, You Use PHP?

Add a comment »

Some Symfony resources

January 15th, 2014

This year my main professional objective will be to learn more about the Symfony framework.
While I still enjoy working with Laravel, Symfony is the main framework I use at work and I want to focus on it. Here are 3 resources I intend to follow:
Create your own framework… on top of the Symfony2 Components
Diving Into Symfony 2

Learning Symfony 2

Add a comment »

Working with relations in Laravel

December 23rd, 2013

Let’s say you have this piece of code:

Can you tell me what is the difference between line 3 and line 5?

When I first started with relationships in Laravel I found them really easy to use, but I couldn’t figure it out what should I use when querying for data: the property or the method?

The property is a collection object

To be more precise is the Illuminate\Database\Eloquent\Collection class. In our case we will have the comments collection loaded for our post. You can check that class out to see what methods supports.

The method is a relation

In our case it would be a Illuminate\Database\Eloquent\Relations\HasMany class. No matter the relation type, they all extend the Illuminate\Database\Eloquent\Relations\Relation abstract class. When using a relation we can add more conditions to our query such as where. Why is that?

The __call() method of Relation class is called when invoking inaccessible methods. So when we add a where clause such as:

We can see on line 10 that the method ‘where’ will be called on this->query with the parameters ‘title’, ‘=’, ‘foo’. And this->query is the query builder: Illuminate\Database\Eloquent\Builder class which will support all these methods.


When you need to access only the collection without any filters use the property, and when you need to use the query builder functionality use the method.

Add a comment »

Upgrade to Laravel 4.1

December 15th, 2013

If you have an application built on Laravel 4.0 and you want to upgrade to 4.1 you can follow the instructions here.

Besides instructions there, you should remove bootstrap/compiled.php file.

If ‘composer update’ command triggers a fatal error with ‘Class ‘Illuminate\Remote\RemoteServiceProvider’ not found’ message:

you should use

command instead of ‘composer update’.

What’s new?

If you’re curios what’s new in 4.1 version you can read the release notes. I’m glad they made the password reminder more flexibile, but I’m not eager to re-implement this. Just yesterday I implemented the remind password on moneytablet.com. Oh well, I need to start over :)

Add a comment »