Plus de 10 années de développement web m'ont amené à travailler pour de multiples secteurs d'activités (e-commerce, industrie, communication, commerce B2B) dans différentes structures (agence web, éditeur logiciel, SSII).
Je suis aujourd'hui en charge du développement des plateformes web chez Kiplin et de la montée en compétences de l'équipe technique.
Symfony 3.2 brings support of PHP constants in YAML
23 août 2017
A nice improvement of Symfony 3.2 is support of PHP constants in YAML files.
This allows to define a service from a class and some constructor parameters defined as PHP constants, all in a services.yml file (no PHP code involved, just inject it !).
Let's try it with a PSR-7 HTTP client :
# Concrete implementation of HTTP client
Classic stuff we need while using Twig : access static properties or call static methods of any class.
Downloadable from my Github repository
class Reflection extends \Twig_Extension
public function getFunctions()
A short post to promote a new tool developed by my friend Alain Tiemblo : TwigFiddle. You can now test your templates, macros, and share your Twig code examples with this tool.
This is really useful when you post or answer a question about a Twig issue on Stackoverflow (or any other dev forum).
So test it and make feedback if you discover an issue or just have any suggestion...
Symfony Security bundle provides everything to deal with redirections after login. The most used is based on referer as many pages may require an authentication, and this way you just redirect to the pages that asked for identification. But what happens when user has no account, he needs to register and create its account. Here is a proper way to achieve redirection after registration, dealing
Doctrine2 optimization with APC cache and Symfony2
13 mai 2014
Some parts of a website are common to every pages and needs to request data from database. To put this data in a cache system is often a first step for optimization. Here is my return on experience about caching data with Doctrine2 in a Symfony2 project.
Before caching data, deal with metadata
Doctrine metadata store informations about entities structure, relations and so on. It's really safe
As a strong user of Doctrine2 since I'm working with Symfony2, I also use Gedmo DoctrineExtensions. This library provides a great set of useful features we commonly need when developping web project :
Timestampable entities (created_at and updated_at columns on tables),
Trace creators and modificators on contents (Blameable behavior)
Since I more often work for sensitive
The need to state EntityManager name in a UniqueEntity validation constraint [Symfony2, Doctrine2]
27 août 2013
I need to code a backoffice that manages many entities of my sites. Each of my sites has its own bundle with its own database, and a dependency to a common bundle with its own "common" database (for users, logging, billing).
For the same reasons, avoid to access default EntityManager from Container, without naming it... It could lead to an error if you embed your bundle in another application
As Symfony (2.0) doc is not very clear on this subject, I spent some time to help a colleague on the following question : How to make HTTPS port different from 443 ?
Of course it's possible, and this is a simple configuration option in app/config.yml :
# router configuration
How to inhibit Soap Security headers "mustUnderstand" attribute in a Symfony2 controller
16 oct. 2012
I never managed to make native PHP SoapServer class to handle "understand" soap:Security header as expected with mustUnderstand attribute. But some WS tools like SoapUI automatically set it to "true" or "1" and I needed to make a work around to avoid Soap Fault : "SOAP-ENV:MustUnderstand / Header not understood"
Here is a controller action that inhib mustUnderstand attribute :
While following Symfony2 WSSE implementation tutorial, I was annoyed by the suggested WSSE headers interpretation. It only presents HTTP headers, not Soap WSSE headers...
Here is an extract of Symfony2 tutorial, handling HTTP headers :
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
How to deal with asynchronous request with Symfony2 and other PHP frameworks
06 août 2012
As well as most of PHP frameworks, Symfony2 manages user session by locking it during request treatment. It avoids concurrent access to session file but makes requests to be queued until session lock is freed...
This behaviour is really well explained in this post from Gareth McCumskey.
As Gareth describes his solution, we need to manually free session lock after all session modifications
I handle a multi-tab form that is validated by one group per form-tab. When I get errors while binding request, I'd like to know the first tab (ie validation group) that is not valid.
Is it possible with Symfony 2.0, and how ?
Please feel free to post your answer on StackOverflow, I will then publish it here. Thanks in advance !
When you want to set a related entity to another one, no need request the related object !
Doctrine ORM provides EntityManager::getReference($entityName, $id) method that only returns a reference to a record, not the entity itself... Let's see it in action :
Set up a specific log file for connections with Symfony2
11 avr. 2012
Symfony2 basically embeds a full-featured logger, Monolog. A default implementation is available as 'logger' service. But you may need to log to a specifi file instead of traditional dev/prod/test.log... This article shows how to define a specific logger for connections.
I don't need to re-code a logger, the default one perfectly works. I just need to define a new file to log in, so a Monolog
Custom form validation constraint with Callback in Symfony2
11 avr. 2012
Symfony2 forms provides many embedded validators to constrain data passed in form fields. Here is the way to define a constraint in a callback function, useful to determine a data validity relative to another field...
Given a form asking the user to chose its favorite payment ways, in a shopping application :
After a few hours spent on pulling out my hair (typical french-speaking), I discovered that underscores in web subdomains are not RFC compliant, and that, for once, Internet Explorer strictly follows RFC recommendations ! No session persistance in IE with an underscore in your subdomain !
How to create a Service to embed business logic functions in Symfony2
05 déc. 2011
Services are classes where you will write the Business Logic code or any other treatment that you want to make accessible to a controller or another service. The Logger delivered with Symfony2 is a service, like the Registry of Doctrine, which gives access to the EntityManager.
The example below shows how to create a service, to pass two services it can use as parameters.
1- We begin by
Set up an AuthenticationSuccessHandler in Symfony2
31 oct. 2011
Symfony2 allows you to simply make treatments after a login attempt success. As simple as you just have to define a service, called "security.authentication.success_handler" and make it to implement AuthenticationSuccessHandlerInterface...
In this example, I want logged new user to be redirected to a "Terms and conditions" accept form. I have to check the boolean property termsAndConditionsOk of
Deal with a nullable relation field in an Entity with Doctrine2
04 oct. 2011
Entity generation from an existing database is a long way to go... Last issue : set a relation field to NULL => the generated setter expects an Entity Object as a parameter
MyEntity is an entity including a field myRelatedEntity referencing an entity MyRelatedEntity. Basic generation produces this setter :
* Set myRelatedEntity
* @param Xxx\
Configuration trick for multiple entity managers in Symfony2
04 oct. 2011
First time I tried to define multiple entity managers in config.yml, i got some errors...
I didn't strictly followed symfony cookbook but based my configuration on the reference about Doctrine configuration. So I let "auto_mapping" parameter with false value, and I got following error :
InvalidConfigurationException: Unrecognized options "auto_mapping" under "doctrine.orm"
So if you want
Deal with MySQL types natively unsupported by Doctrine2
18 sept. 2011
Some types of data, specific to MySQL are not supported by Doctrine2 when generating the mapping and entities from an existing database (reverse engineering).
Nevertheless, there remains the possibility to easily convert them into basic types. Example with ENUM, VARBINARY and TINYBLOB types.
Everything goes in app/config.yml, in the "doctrine" section (only conf, very convenient), see the "
APC is the most well-known caching system for PHP, and maybe one of the simpliest. Symfony2 strongly suggests to enable it, as well on development than production environment.
Sf2 natively uses APC to cache PHP files as OPCODE. But you can cache what you want in your code, any kind of PHP data.
APC makes the distinction between PHP OPCODE cache and custom cache :
File cache gets PHP OPCODE,
As i apply a redirection after switching language, i'd like to send a cookie to store the last selected language for the user. But Symfony2 RedirectResponse default constructor doesn't allow to do this....
Here is a class extanding RedirectResponse that takes an array of Cookie objects as third parameters :
This component is downloadable and forkable on my Git repository : http://github.com/