PHP and design patterns : a smart way ?

Thanks to Jon Lemaitre’s excellent article “A Response to PHP the wrong way“, I recently discovered http://phpthewrongway.com self-exposed as the counterbalance of http://phptherightway.com. Then came the need to write an answer on the subject, my views on framework, OOP, standards and the rest but I realized I would end up with a very long article full of obvious arguments or at least statements many people already know. Boring. Seriously who wants to read another pros and cons on frameworks and OOP ? Is it really worth discussing it nowadays, knowing how many classes are offered by PHP itself and how its own syntax is object oriented ? I just think that if you don’t want to write OOP code with PHP, you’re free to use another language or to fork PHP 3.

The only subject I will cover in this post is the usage of design patterns. It could have been the wisest part of “PHP the wrong way” but the author failed to provide relevant arguments by focusing on a philosophical point of view. My goal here is to bring a more objective point of view with technical facts.

The wrong way: Looking for a pattern to solve a problem

True, this is a dogmatic approach we must stay away from. Patterns were designed to implement common needs like separation of responsibilities, open/close principle and to save some precious time finding design solutions. However, it has some drawbacks and the use of design patterns requires skills and common sense.

Continue reading

A successful upgrade from Symfony 2 to 3

As Feed-io-bundle is now Symfony 3 compliant, the next logical move was to upgrade its demo. The application is just composed of the bundle itself and Bootstrap so the upgrade process should be easy to follow. Let’s see what’s in the documentation :

There are a couple of steps to upgrading a major version:

  1. Make your code deprecation free
  2. Update to the new major version via Composer
  3. Update your code to work with the new version

Three steps and every thing seems cristal clear, here we go.

Replace deprecated code and configuration

According to the cookbook, you’ll have to replace everything that became deprecated during Symfony 2’s evolution. To go through the first step, Symfony provides a package called symfony/phpunit-bridge which detects deprecated parts of your code and shows you the way to correct it. Another way to go is to pay attention to deprecations Symfony notices to your application’s log, which means to manually test the whole application. Good luck with that. feedio-demo has unit tests (well in fact, one), I’ll use the bridge :

image

OK, that’s easy. Only one configuration to fix and feedio-demo is ready for the dependencies upgrade.

Continue reading

A factory in feed-io v2.2

In feed-io 2.2, I introduced a Factory class built to get a FeedIo instance in one single line of code :

$feedIo = \FeedIo\Factory::create()->getFeedIo();

Obviously this works assuming that you installed feed-io using Composer and you have included vendor/autoload.php before.

Factory’s main method : Factory::create()

The factory comes with the ability to configure feed-io before getting its main class. For that, you will provide one or two configuration arrays depending on which dependency you want to configure.

Continue reading

feed-io-bundle 3.0 to support Symfony 3.0

Edit : the bundle is no longer supported, see this announcement

I recently released version 3.0 of feed-io-bundle. Symfony 3.0 introduced a backward compatibility break in forms support, so it became impossible to maintain a code base compatible with both versions.

Symfony 2.x support

I created a branch called release/2.x to maintain feed-io-bundle version 2. It will last until the end of the Symfony 2.x official support. This branch will be used for bug fixes only, all the new features will be committed to the master branch.

To write PHP applications with Android : use GNURoot Debian

In a previous post I wrote about the possibility to develop PHP applications using a tablet. The main trouble was to find a reliable application to run a web server with a recent version of PHP featuring xDebug and the ability to run unit tests. It’s manageable but not fully satisfying so I kept looking for another solution.

Then I found GNURoot Debian and it changed everything : Debian Jessie running inside a virtual machine, you can’t ask for more.

I tried several Linux emulators and GNURoot Debian was the only one to work easily without tweaking its configuration. For instance, LinuxDeploy seems very powerful but it never managed to write its configuration on the file system. Even the higher level of logging didn’t point out what the real problem was.

Continue reading

Coding everywhere using an Android device

screen-shot

Some while ago, I used to code with my laptop on my knees in the public transportation. That way, I made significants contributions to rss-atom-bundle and I’m sure this bundle wouldn’t be the same today without it. Meanwhile, coding with a 15” laptop in the subway means troubles with other passengers or the laptop itself like complaints, purse shots in the screen or a computer getting very hot on your knees. So I decided to keep it home.

But I couldn’t resist, I needed to keep working on open source projects so I tried to do it with a system closed to what I know on a smaller device. The Nexus 7 tablet is a good candidate for that and you’ll see in this post how I managed to set up a development environment using applications available on Google Play. I ended up with the ability to push commits on Github and to run PHPunit inside my projects.

Continue reading