For debugging purposes, it's sometimes usefull to print the queries executed by a Symfony2 Command. Here is my tiny piece of code to do it. protected function execute(InputInterface $input, OutputInterface $output) { // your code here // printing sql queries $logger = […]
Coding
[Symfony] Coupling sfDoctrineGuardPlugin and fail2ban
Recently I created a quite sensible application using symfony 1.4. As many people, I chose sfDoctrineGuardPlugin as authentication/password recovery/account managing system. But even with this piece of software, you are still vulnerable to bruteforce attacks.
I though of hacking sfDoctrineGuardPlugin's code to create some rules and attack detections. But those systems are quite tricky to create and calibrate. It must not be too aggressive nor too permissive. I wanted something that can bail out someone after $some tries in a $certain time. That implied that I would have to record every try with the current time, and calculate a ratio within which a user can login or not. I seemed simple, then it got too complicated.
Symfony - Doctrine: Use a fully UTF8 database
First, edit your config/databases.yml and add : [yml] all: doctrine: class: sfDoctrineDatabase param: dsn: mysql:socket=/var/run/mysqld/mysqld.sock;dbname=mydb username: mydb password: mypassword encoding: utf8 attributes: default_table_collate: utf8_unicode_ci default_table_charset: utf8 Then open […]
Doctrine: Howto bypass the SoftDelete behaviour
For one of my projects I have to check if a record already exists in my database, deleted or not. The preDqlSelect looks like this : /** * Implement preDqlSelect() hook and add the deleted flag to all queries for which this model * is being used in. * * @param Doctrine_Event $event * @return void */ […]
Notify: New release of the aMSN plugin
A new release of the Notify plugin for aMSN is now available. You can download it on http://www.amsn-project.net/plugins.... Changelog: Fix UTF8 detection, thanks to bardo Version 1.5 […]
PHP bench: count + for vs foreach vs while
I tested different loops. Here is my test script : ┌─(yoda@ev5)(14:32:05) └─(~/var/www/test)-> cat for_foreach_while.php #!/usr/bin/php <?php define('N', "\n"); error_reporting(E_ALL | E_NOTICE); $nbLoop = 10000; $testArray = array_fill(0, 500, 'toto'); $time = array(); […]
Symfony: Validate fields depending of another field (update 2010-02-23)
It's possible, when validating a form, to check if a field is correct dependently of an other field's value. First, in your configure method, after the declaration of your validators, add : $this->validatorSchema->setPostValidator( new sfValidatorCallback( array('callback' => array($this, […]
Symfony: change the default type of your primary keys
Hey, yes it's possible to change the default type of your primary keys with a simple configuration Open your config/databases.yml. It should looks like this : [yml] # You can find more information about this file on the symfony website: # http://www.symfony-project.org/reference/1_4/en/07-Databases […]
Symfony, tasks and return values
In symfony, it's possible to return a value in your execute() method. Let's create a test task : ┌─(yoda@box)(09:46:59) └─(~/var/www/test)-> ./symfony generate:task test >> task Creating "/home/yoda/var/www/test.../testTask.class.php" task file Adding a return value at the end of […]
[Symfony] Overwrite a value in a form
It happen sometimes that you have to set/override a value within a form but without using a hidden field (that can be overridden) Here is a short solution to set the user id in the object we are going to save. Let's say that we have an object PersonnalData linked to the sfGuardUserProfile In your […]
[Symfony] Load an sql dump within a task
I recently had a problem when loading fixtures in my symfony project. I was loading cities, about 37 000 of them, and the doctrine:data-load was extremly slow (about 5 minutes). I finally found a solution to load an sql dump wihtin a task, using the doctrine/default connection. With this solution, I […]
[PHP] Pensez à STDClass
Il arrive souvent qu'on ai besoin de retourner plusieurs informations distinctes dans une fonction ou une méthode. La plupart du temps, il suffit de retourner un tableau indexé de manière intelligente. class CSS { public function getDeclaration($pDeclaration) { list($key, $value) = explode(':', […]
My first plugin for symfony
Hey, I just uploaded my first plugin for symfony ! This plugin is a simple wrapper for a jQuery Carousel found at http://sorgalla.com/projects/jcarousel/
MPD Remote control script v0.2
Here is a new version of my console mpd remote script.
Recomposer un HTML valide après l'avoir tronqué.
Récemment, je me suis occupé de la création d'un site web tout joli tout beau, dans lequel les webmasters peuvent composer certaines parties de leur site web via un éditeur online wysiwyg. Mais à certains endroits, j'avais besoin de mettre juste le début du texte suivi des traditionnels 3 petits points.
Notify plugin for aMSN updated (1.3)
New version of my notify plugin for aMSN Changelog: Added "dash hack" : http://www.amsn-project.net/forums/viewtopic.php?t=5847, thanks to nico@nc Re-enable sounds on events: http://www.amsn-project.net/forums/viewtopic.php?t=5824 , thanks to nico@nc too bumped to version 1.3 Download the […]
MPD Remote control script
Hey, i'm still looking for my best audio player. At the moment i'm testing MPD with Sonata as Front-end. Unfortunately, mpd doesn't come with a remote controle system that can be used with my Logitech keyboard. So I managed to write mine. You'll need Audio::MPD, which is aviable in Debian with […]
Plugin Notify for aMSN
Here is a new version of my plugin called Notify. Changelog : I was using wrong aMSN's preferences Fixed when the header is empty (setting "aMSN") This plugin replace aMSN's own notification system by using libnotify. It actually support : Display of your contact picture Uses of aMSN's […]
Developer toolbar for Internet Explorer
I'm currently making a website with a complicated design. I use to play with Firebug to controle layers placement, to trace unwanted margins and so many strange html behaviors. But ... Internet Explorer is a crappy piece of program ! If Firefox make some strange things, Internet Explorer is doing really what it wants.
So I tried to find out an equivalent of Firebug for Internet Explorer. I know that Firebug exists as a javascript script, but I didn't want to change my code just for that.
Javascript (Bon à savoir)
J'avais écrit un code du genre pour afficher/cacher un div à la con : function toggleVis(pDiv) { item = document.getelementbyid(pDiv); if(item.style.display == "none") { item.style.display = "block"; return true; } item.style.display = "none"; return true; } Sous […]