Hi, I'm Matthieu Napoli!

These are thoughts and experiments about web development and programming.

23 November 2012

The PHP-FIG should define PHP interfaces

Bouncing on the discussion initiated in the #52 ticket of the PHP-FIG project on Github: « Explain the scope of the PSR system », I’ll explain the case I’m trying to make.

First, PHP-FIG, which stands for Framework Interoperability Group, is a gathering of major PHP frameworks and project who try to:

talk about the commonalities between our projects and find ways we can work together.

This group has released PSR-0, PSR-1 and PSR-2, three specifications of coding standards, guide style and code organisation (for autoloading interoperability). Now the question is asked: is it the role of the PHP-FIG to define technical “code” specifications or is it out of its scope? Here is my answer.

PSR-0/1-2 are contracts between its users to ensure cohesiveness and compatibility.


05 October 2012

Doctrine 2 YAML reference

If you are working with Doctrine 2 and its YAML configuration files for the object mapping, you may find the documentation lacking some details.

Here is a gist of all the YAML syntax possible:


20 September 2012

Dependency Injection with PHP

I used to develop using Singletons, registries or even static classes. Those days are gone.

I decided to use Dependency Injection so that:

  • my classes would be testable
  • replacing an implementation by another would be not only doable, but easy (and so extending a library/module would too)
  • the design of those classes wouldn’t be guided by the question of “how they will be used”
  • my code would be cleaner, simpler
  • and IDE auto-completion/type-hinting would always work

I gave a try to Symfony and ZF2 DI systems, but they both seem way too complicated for just a simple need (that anyone who has worked with Spring would understand):

class MyClass {
    /**
     * @Inject
     * @var MyService
     */
    private $service;
}

This short code means: Inject, using a simple annotation, an instance of another class into a property.

I started working on a framework enabling such functionality few months ago. It is now in a mature state. It is based on the Annotations library of Doctrine 2, and takes most of its ideas of Spring 3.

You can check out this framework on its official website: PHP-DI, and you are welcome to use it or contribute.